This article mainly introduces how to implement openssl-based encryption and decryption in php, and analyzes the encryption and decryption operations related to php user-defined functions based on openssl in the form of examples, for more information about how to implement openssl-based encryption and decryption in php, see the example in this article. We will share this with you for your reference. The details are as follows:
Openssl encryption and decryption methods
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 = '000000'; // decryption key $ 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 ;}}
I hope this article will help you with PHP programming.
For more articles about how to implement openssl-based encryption and decryption methods in php, refer to PHP Chinese network!