[Laravel5.2 documentation] service-encryption

Source: Internet
Author: User
Tags crypt
[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) {    //}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.