Home >Backend Development >PHP Tutorial >PHP uses mcrypt to perform encryption and decryption functions

PHP uses mcrypt to perform encryption and decryption functions

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 09:10:42942browse
  1. // Encrypt Function
  2. function mc_encrypt($encrypt, $mc_key) {
  3. $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
  4. $passcrypt = trim(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $mc_key, trim($encrypt), MCRYPT_MODE_ECB, $iv));
  5. $encode = base64_encode($passcrypt);
  6. return $encode;
  7. }
  8. // Decrypt Function
  9. function mc_decrypt($decrypt, $mc_key) {
  10. $decoded = base64_decode($decrypt);
  11. $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB), MCRYPT_RAND);
  12. $decrypted = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $mc_key, trim($decoded), MCRYPT_MODE_ECB, $iv));
  13. return $decrypted;
  14. }
  15. ?>
复制代码


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