How do you Encrypt and Decrypt a PHP String?

后端 未结 10 1678
梦毁少年i
梦毁少年i 2020-11-22 01:21

What I mean is:

Original String + Salt or Key --> Encrypted String
Encrypted String + Salt or Key --> Decrypted (Original String)

May

10条回答
  •  温柔的废话
    2020-11-22 01:36

    For Laravel framework

    If you are using Laravel framework then it's more easy to encrypt and decrypt with internal functions.

    $string = 'Some text to be encrypted';
    $encrypted = \Illuminate\Support\Facades\Crypt::encrypt($string);
    $decrypted_string = \Illuminate\Support\Facades\Crypt::decrypt($encrypted);
    
    var_dump($string);
    var_dump($encrypted);
    var_dump($decrypted_string);
    

    Note: 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.

提交回复
热议问题