IEncryptor
in
Interface for encryption/decryption implementations
Provides a contract for different encryption methods to implement, allowing the framework to support various encryption algorithms and libraries (OpenSSL, Sodium, etc.)
Table of Contents
Methods
- decrypt() : string
- Decrypt data using the provided key
- encrypt() : string
- Encrypt data using the provided key
- generateKey() : string
- Generate a random encryption key
- getCipher() : string
- Get the cipher algorithm name
- isValidKey() : bool
- Validate that a key meets the requirements for this encryptor
Methods
decrypt()
Decrypt data using the provided key
public
decrypt(string $encryptedData, string $key) : string
Parameters
- $encryptedData : string
-
The encrypted data (base64 encoded)
- $key : string
-
The decryption key
Tags
Return values
string —The decrypted plaintext data
encrypt()
Encrypt data using the provided key
public
encrypt(string $data, string $key) : string
Parameters
- $data : string
-
The plaintext data to encrypt
- $key : string
-
The encryption key
Tags
Return values
string —The encrypted data (base64 encoded for safe storage)
generateKey()
Generate a random encryption key
public
generateKey() : string
Tags
Return values
string —A cryptographically secure random key
getCipher()
Get the cipher algorithm name
public
getCipher() : string
Return values
string —The name of the cipher algorithm used
isValidKey()
Validate that a key meets the requirements for this encryptor
public
isValidKey(string $key) : bool
Parameters
- $key : string
-
The key to validate
Return values
bool —True if the key is valid