时间:2021-07-01 10:21:17 帮助过:11人阅读
通过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; } }
希望本文所述对大家PHP程序设计有所帮助。
更多php实现基于openssl的加密解密方法相关文章请关注PHP中文网!