Encryption
Before using Lumens's encrypter, you should set the option of your .env
file to a 32 character, random string. If this value is not properly set, all values encrypted by Lumen will be insecure.
Basic Usage
Encrypting A Value
You may encrypt a value using the Crypt
facade. All encrypted values are encrypted using OpenSSL and the AES-256-CBC
cipher. Furthermore, all encrypted values are signed with a message authentication code (MAC) to detect any modifications to the encrypted string.
Decrypting A Value
Of course, you may decrypt values using the method on the Crypt
facade. If the value can not be properly decrypted, such as when the MAC is invalid, an Illuminate\Contracts\Encryption\DecryptException
will be thrown:
use Illuminate\Contracts\Encryption\DecryptException;
$decrypted = Crypt::decrypt($encryptedValue);
} catch (DecryptException $e) {
}