This article mainly introduces the implementation of encryption and decryption methods based on openssl in PHP, and analyzes PHP in the form of examplesCustom functionsRelevant techniques for implementing encryption and decryption operations based on openssl, friends in need can refer to the following
The example of this article describes the encryption and decryption method based on openssl in PHP. Share it with everyone for your reference, the details are as follows:
Encryption and decryption method through openssl
1. openssl encryption method:
function encrypt($id){ $id=serialize($id); $key="1112121212121212121212"; $data['iv']=base64_encode(substr('fdakinel;injajdji',0,16)); $data['value']=openssl_encrypt($id, 'AES-256-CBC',$key,0,base64_decode($data['iv'])); $encrypt=base64_encode(json_encode($data)); return $encrypt; }
2. openssl decryption method:
function decrypt($encrypt) { $key = '1112121212121212121212';//解密钥匙 $encrypt = json_decode(base64_decode($encrypt), true); $iv = base64_decode($encrypt['iv']); $decrypt = openssl_decrypt($encrypt['value'], 'AES-256-CBC', $key, 0, $iv); $id = unserialize($decrypt); if($id){ return $id; }else{ return 0; } }
The above is the detailed content of Detailed explanation of examples of encryption and decryption methods based on openssl in PHP. For more information, please follow other related articles on the PHP Chinese website!