Simple AES encryption and decryption algorithm implemented in PHP

墨辰丷
Release: 2023-03-27 11:00:02
Original
2387 people have browsed it

This article mainly introduces the simple AES encryption and decryption algorithm implemented by PHP, and analyzes the related operation skills of PHP for string encryption and decryption based on mcrypt_encrypt, bin2hex, mcrypt_decrypt and other methods based on specific examples. Friends in need can refer to the following

The example in this article describes the simple AES encryption and decryption algorithm of PHP. Share it with everyone for your reference, the details are as follows:

/*
* 实现AES加密
* $str : 要加密的字符串
* $keys : 加密密钥
* $iv : 加密向量
* $cipher_alg : 加密方式
*/
function ecryptdString($str,$keys="6461772803150152",$iv="8105547186756005",$cipher_alg=MCRYPT_RIJNDAEL_128){
  $encrypted_string = bin2hex(mcrypt_encrypt($cipher_alg, $keys, $str, MCRYPT_MODE_CBC,$iv));
  return $encrypted_string;
}
/*
* 实现AES解密
* $str : 要解密的字符串
* $keys : 加密密钥
* $iv : 加密向量
* $cipher_alg : 加密方式
*/
function decryptStrin($str,$keys="6461772803150152",$iv="8105547186756005",$cipher_alg=MCRYPT_RIJNDAEL_128){
  $decrypted_string = mcrypt_decrypt($cipher_alg, $keys, pack("H*",$str),MCRYPT_MODE_CBC, $iv);
  return $decrypted_string;
}
Copy after login

## Related recommendations:

php implements DES that is consistent with c#encryption and decryptionmethod

PHP’s RSA Encryption and decryptionUsage analysis of development interface cases

##PHP implements SSL

Encryption and decryption, verification and signature

##

The above is the detailed content of Simple AES encryption and decryption algorithm implemented in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template