Laravel 5: Decrypting Strings With decrypt

April 14, 2018 —John Koster

The decrypt helper function can be used to decrypt the provided value. The function resolves the configured "Illuminate\Contracts\Encryption\Encrypter" implementation from the Service Container and then calls the decrypt method on the Encrypter instance.

#Signature

The signature of the decrypt function is:

1function decrypt(
2 $value
3);

#Example Use

Assuming a variable $encryptedValue exists and contains a previously encrypted value the following examples are all equivalent:

1use Illuminate\Support\Facades\Crypt;
2 
3$encryptedValue = '...';
4 
5// Decrypt using the Crypt facade:
6Crypt::decrypt($encryptedValue);
7 
8// Decrypt using the decrypt helper:
9decrypt($encryptedValue);
10 
11// Resolve an instance from the Service Container.
12app('encrypter')->decrypt($encryptedValue);
13 
14// Resolve an instance from the Service Container.
15resolve('encrypter')->decrypt($encryptedValue);

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.