The Crypt Service provides functionality for AES encryption using via the \Defuse\crypto library, and hashing using the sha512 algorithm.

You must configure your AES_KEY256 setting variable key to use encryption.

This is done for you on install and can also be accomplished via the disco CLI.


You should configure your SHA512_SALT setting variable to a random key of any length for your hashing to be more secure.

This is done for you on install and can also be accomplished via the disco CLI.

Example Usage #

// Encryption
$crypt = Crypt::encrypt('Super secret string!');

// Decryption
$plain = Crypt::decrypt($crypt);

// If you want to use a unique key that only is paired with certain data, say with a certain users info you can generate a new key,
// save it, and use it for the encryption and decryption for that user
$key = Crypt::generateNewCryptKey();
$crypt = Crypt::encrypt('The secret', $key);

$decrypt = Crypt::decrypt($crypt,$key);


// 1 way hashing
$hash = Crypt::hash('some password');

// Hash with a new salt and return both the hashed data and the new salt
$message = 'Get it hashed!';
$data = Crypt::hashAndGenerateNewSalt($message);

echo $data['hash']; // the hashed value
echo $data['salt']; // the salt used to hash

// reperform the hash
$hash = Crypt::hash($message,$data['salt']);

// they will be equal
$equal = $hash == $data['hash'];