手机
当前位置:查字典教程网 >编程开发 >php教程 >php实现基于openssl的加密解密方法
php实现基于openssl的加密解密方法
摘要:本文实例讲述了php实现基于openssl的加密解密方法。分享给大家供大家参考,具体如下:通过openssl加密解密方法1.openssl加...

本文实例讲述了php实现基于openssl的加密解密方法。分享给大家供大家参考,具体如下:

通过openssl加密解密方法

1. openssl加密方法:

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; }

2. openssl解密方法:

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; } }

PS:关于加密解密感兴趣的朋友还可以参考本站在线工具:

密码安全性在线检测:

http://tools.jb51.net/password/my_password_safe

高强度密码生成器:

http://tools.jb51.net/password/CreateStrongPassword

MD5在线加密工具:

http://tools.jb51.net/password/CreateMD5Password

迅雷、快车、旋风URL加密/解密工具:

http://tools.jb51.net/password/urlrethunder

在线散列/哈希算法加密工具:

http://tools.jb51.net/password/hash_encrypt

希望本文所述对大家PHP程序设计有所帮助。

【php实现基于openssl的加密解密方法】相关文章:

php简单实现多字节字符串翻转的方法

JavaScript实现滚动栏效果的方法

php中smarty实现多模版网站的方法

用php实现gb2312和unicode间的编码转换

php实现比较两个字符串日期大小的方法

PHP+shell实现多线程的方法

基于qmail的完整WEBMAIL解决方案安装详解

PHP实现的增强性mhash函数

php实现根据IP地址获取其所在省市的方法

php中PDO方式实现数据库的增删改查

精品推荐
分类导航