$key
$key : string
This class represents a secret key for the symmetric encryption engine.
Note: This class uses OpenSSL for strong encryption
generate(string $password, integer $keyLength = 16) : string
Generate the hexadecimal representation of a secure key using a salt algorithm in order to derive it from the given password.
Note: once generated the key cannot be retrieved... you MUST save the key for future usage.
string | $password | the password to be derived |
integer | $keyLength | the final length of the key (in bytes) |
invalid arguments have been passed
the error occurred while generating the requested hashing algorithm
an hex representation of the generated key
__construct(string $key)
Create an encryption key using the given serialized key.
A serialized key is the hexadecimal representation of key.
You can use the generate() function to retrive a really secure key from the password (the same key derivation algorithm that openssl internally uses).
Usage example:
//generate a secure pbkdf2-derived key and use it as the encryption key
$my_key = new SecretKey(SecretKey::generate("mypassword"));
//you MUST save the generated key, because it won't be possible to //generate the same key once again (even using the same password)! $precious_key = (string) $my_key;
string | $key | the password to be used in a HEX encoded format |