This article describes the implementation of PHP based on OpenSSL encryption and decryption method. Share to everyone for your reference, specific as follows:
Encryption and decryption by OpenSSL method
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;
}
PS: About encryption and decryption interested friends can also refer to the site online tools:
Password Security online detection:
Http://tools.jb51.net/password/my_password_safe
High Strength Password Generator:
Http://tools.jb51.net/password/CreateStrongPassword
MD5 Online Encryption Tool:
Http://tools.jb51.net/password/CreateMD5Password
Thunderbolt, Express, Cyclone URL encryption/decryption tool:
Http://tools.jb51.net/password/urlrethunder
Online hashing/hashing algorithm encryption tool:
Http://tools.jb51.net/password/hash_encrypt
For more information on PHP related content readers can view the site topics: "PHP Encryption Method Summary", "PHP code and transcoding Operation Skills Summary", "PHP object-oriented Program Design Introductory Course", "PHP Mathematical Arithmetic Skills summary", "PHP Array" operation Skills Encyclopedia, " Summary of PHP string usage, PHP data structure and algorithm tutorial, PHP programming algorithm Summary, PHP Regular Expression usage summary, and PHP Common database operation Skills Summary
I hope this article will help you with your PHP programming.