下面展示一些 内联代码片 。 vue
// A code block
打开终端
npm install crypto-js
代码
<script>
import CryptoJS from "crypto-js"
export default {
data() {
return {
text:''
}
},
onShow() {
let params = {
id: 1,
status: 2,
fields: JSON.stringify({
name: '潘',
sex: "男"
})
}
this.text=this.encrypt(JSON.stringify(params), 'key一定要16位', 'vi一定要16位')
},
methods: {
encrypt(str, KEY, IV) {
var key = CryptoJS.enc.Utf8.parse(KEY);
var iv = CryptoJS.enc.Utf8.parse(IV);
var encrypted = CryptoJS.AES.encrypt(str, key, {
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
return encrypted.toString();
}
}
}
</script>
php代码
if (empty($time)) $time=date('YmdHis',time());
if (abs(strtotime(date($time)) - time())>=10) throw new \Exception('请核对您设备时间','10000');
$key = 'key一定要16位';
$iv = 'vi一定要16位';
$test= openssl_decrypt(base64_decode($request->data),"AES-128-CBC",$key,true,$iv);
$test = htmlspecialchars_decode($test);
$test=json_decode($test,true);
return json([
'data'=>$test
]);
|