AES_CBC_128
AES_CBC_128
This class represents an algorithm collection for the asymmetric encryption engine.
Note: This class uses OpenSSL for strong encryption
encrypt(\Gishiki\Security\Encryption\Symmetric\SecretKey $key, string $message, string|null $initVector = null, string $algorithm = self::AES_CBC_128) : array
Encrypt the given content using the given secure key (that should be prepared using pbkdf2).
The resulting IV (automatically generated if null is passed) is base64 encoded.
The resulting encrypted content is base64 encoded.
Example usage:
//prepare the secret key for the symmetric cipher
$key = new SecretKey( ... );
//Note: the key is NOT the password
//encrypt the content $enc_result = Cryptography::encrypt($key, "this is the message to be encrypted");
//transmit the IV_base64 and Encryption to decrypt the content //if you used a cistom IV you don't need to pass the IV
\Gishiki\Security\Encryption\Symmetric\SecretKey | $key | the key to be used to encrypt the given message |
string | $message | the message to be encrypted |
string|null | $initVector | the base64 representation of the IV to be used (pick a random one if null) |
string | $algorithm | the name of the algorithm to be used |
one or more arguments are invalid
the error occurred while encrypting the content
the base64 of the raw encryption result and the used IV
decrypt(\Gishiki\Security\Encryption\Symmetric\SecretKey $key, string $encryptedMessage, string $initVector, string $algorithm = self::AES_CBC_128) : string
Decrypt the given encrypted content using the given secure key (that should be prepared using pbkdf2 Ahead Of Time).
Example Usage:
//this is the key encoded in hex format required to create the SecureKey
$key_hex_encoded = " ... "; //make sure this is the key used when encrypting
//Note: the key is NOT the password
//build the key $key = new SecretKey($key_hex_encoded);
//this is the IV encoded in base64: it is returned by the encrypt() function $initVector_base_encoded = " ... ";
//$message will hold the original plaintext message $message = Cryptography::decrypt($key, $encryptedMessage, $initVector_base_encoded);
\Gishiki\Security\Encryption\Symmetric\SecretKey | $key | the key that has been used to encrypt the message |
string | $encryptedMessage | the encryption result (must be base64-encoded) |
string | $initVector | the iv represented in base64 |
string | $algorithm | the name of the algorithm to be used |
one or more arguments are invalid
the error occurred while decrypting the content
the decrypted content