Skip to content

WARNING You're browsing the documentation for an old version of Laravel. Consider upgrading your project to Laravel 12.x.

Encryption

Introduction

Laravel provides facilities for strong AES encryption via the Mcrypt PHP extension.

Basic Usage

Encrypting A Value

1$encrypted = Crypt::encrypt('secret');

Be sure to set a 16, 24, or 32 character random string in the key option of the config/app.php file. Otherwise, encrypted values will not be secure.

Decrypting A Value

1$decrypted = Crypt::decrypt($encryptedValue);

Setting The Cipher & Mode

You may also set the cipher and mode used by the encrypter:

1Crypt::setMode('ctr');
2 
3Crypt::setCipher($cipher);

Laravel is the most productive way to
build, deploy, and monitor software.