Home  >  Article  >  Backend Development  >  AES encryption and decryption of php

AES encryption and decryption of php

WBOY
WBOYOriginal
2016-07-25 08:42:261049browse

PHP code, PHP provides many things, you can use functions directly, but PHP currently only knows the filling mode ZeroPadding, so other languages ​​​​can only follow it:

  1. $privateKey = "1234567812345678";
  2. $iv = "1234567812345678";
  3. $data = "Test String";
  4. //Encryption
  5. $encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $privateKey, $data, MCRYPT_MODE_CBC, $iv);
  6. echo( $encrypted);
  7. echo '
    ';
  8. echo(base64_encode($encrypted));
  9. echo '
    ';
  10. //Decrypt
  11. $encryptedData = base64_decode("2fbwW9+ 8vPId2/foafZq6Q==");
  12. $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $privateKey, $encryptedData, MCRYPT_MODE_CBC, $iv);
  13. echo($decrypted);
  14. ?>
Copy code

Encryption and decryption, php, AES


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Use of PHPZipNext article:Use of PHPZip