本文实例讲述了php实现基于openssl的加密解密方法。分享给大家供大家参考,具体如下:
[b]通过openssl加密解密方法[/b]
[b]1. openssl加密方法:[/b]
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;
}
[b]2. openssl解密方法:[/b]
function decrypt($encrypt)
{
$key = '1112121212121212121212';//解密钥匙
$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;
}
}
[b]
PS:关于加密解密感兴趣的朋友还可以参考本站在线工具:[/b]
[b]密码安全性在线检测:[/b]
[b]
[url=http://tools.jb51.net/password/my_password_safe]http://tools.jb51.net/password/my_password_safe[/url][/b]
[b]高强度密码生成器:[/b]
[url=http://tools.jb51.net/password/CreateStrongPassword][b]http://tools.jb51.net/password/CreateStrongPassword[/b][/url]
[b]MD5在线加密工具:[/b]
[url=http://tools.jb51.net/password/CreateMD5Password][b]http://tools.jb51.net/password/CreateMD5Password[/b][/url]
[b]迅雷、快车、旋风URL加密/解密工具:[/b]
[url=http://tools.jb51.net/password/urlrethunder][b]http://tools.jb51.net/password/urlrethunder[/b][/url]
[b]在线散列/哈希算法加密工具:[/b]
[url=http://tools.jb51.net/password/hash_encrypt][b]http://tools.jb51.net/password/hash_encrypt[/b][/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/43.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]》、及《[url=http://www.1sucai.cn/Special/231.htm]php常见数据库操作技巧汇总[/url]》
希望本文所述对大家PHP程序设计有所帮助。