PHP implementation of OpenSSL-based encryption and decryption Method Example detailed

Source: Internet
Author: User
This article mainly introduces the PHP implementation based on OpenSSL encryption and decryption method, combined with the example form analysis of PHP custom function implementation based on OpenSSL encryption and decryption operations related skills, the need for friends can refer to the next

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; }}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.