本文实例讲述了PHP简单AES加密解密算法。分享给大家供大家参考,具体如下:
/*
* 实现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;
}
[b]PS:关于加密解密感兴趣的朋友还可以参考本站在线工具:[/b]
[b]文字在线加密解密工具(包含AES、DES、RC4等):
[/b][url=http://tools.jb51.net/password/txt_encode]http://tools.jb51.net/password/txt_encode[/url]
[b]MD5在线加密工具:
[/b][url=http://tools.jb51.net/password/CreateMD5Password]http://tools.jb51.net/password/CreateMD5Password[/url]
[b]在线散列/哈希算法加密工具:
[/b][url=http://tools.jb51.net/password/hash_encrypt]http://tools.jb51.net/password/hash_encrypt[/url]
[b]在线MD5/hash/SHA-1/SHA-2/SHA-256/SHA-512/SHA-3/RIPEMD-160加密工具:
[/b][url=http://tools.jb51.net/password/hash_md5_sha]http://tools.jb51.net/password/hash_md5_sha[/url]
[b]在线sha1/sha224/sha256/sha384/sha512加密工具:
[/b][url=http://tools.jb51.net/password/sha_encode]http://tools.jb51.net/password/sha_encode[/url]
更多关于PHP相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/144.htm]php加密方法总结[/url]》、《[url=http://www.1sucai.cn/Special/459.htm]PHP编码与转码操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/630.htm]PHP数学运算技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/623.htm]PHP数组(Array)操作技巧大全[/url]》、《[url=http://www.1sucai.cn/Special/47.htm]php字符串(string)用法总结[/url]》、《[url=http://www.1sucai.cn/Special/614.htm]PHP数据结构与算法教程[/url]》、《[url=http://www.1sucai.cn/Special/111.htm]php程序设计算法总结[/url]》及《[url=http://www.1sucai.cn/Special/180.htm]php正则表达式用法总结[/url]》
希望本文所述对大家PHP程序设计有所帮助。