[Laravel5.2 documentation] service-encryption
1. configuration
Before using Laravel encryptor, set the key option to a 32-bit random string in config/app. php of the configuration file. If this value is not set, all Laravel encrypted values are insecure.
2. Basic use
2.1 Encryption
You can use the Crypt door to encrypt data, and all encryption values are encrypted using the OpenSSL and AES-256-CBC passwords. In addition, all encryption values use a message authentication code (MAC) to detect any modifications to the encryption string.
For example, we can use the encrypt method to encrypt the secret attribute and store it to the Eloquent model:
fill([ 'secret' => Crypt::encrypt($request->secret) ])->save(); }}
2.2 decryption
Of course, you can use the decrypt method on the Crypt facade for decryption. If the value cannot be decrypted, for example, if the MAC is invalid, an Illuminate \ Contracts \ Encryption \ DecryptException exception will be thrown:
use Illuminate\Contracts\Encryption\DecryptException;try { $decrypted = Crypt::decrypt($encryptedValue);} catch (DecryptException $e) { //}