In this paper, an example of PHP implementation based on OpenSSL encryption and decryption method is described. Share to everyone for your reference, as follows:
Encryption and decryption method via 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 ';//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 is helpful to you in PHP programming.