<script src="{{ asset('admin/layui/aes.js') }}"></script>
<script src="{{ asset('admin/layui/pad-zeropadding.js') }}"></script>
前端代碼:
var pwd=$("#LAY-user-login-password").val();
var key = CryptoJS.enc.Utf8.parse('1a1a1a1b1e1c1s12');
var iv = CryptoJS.enc.Utf8.parse('1111111111111111');
var encrypted = CryptoJS.AES.encrypt(pwd, key, { iv: iv, mode: CryptoJS.mode.CBC, padding: CryptoJS.pad.ZeroPadding });
var msg = encrypted.toString();//結果為加密后的字符串
后端代碼:
$privateKey = "1a1a1a1b1e1c1s12";
$iv = "1111111111111111";
$decrypted = openssl_decrypt($data['md5_password'],'aes-128-cbc',$privateKey,OPENSSL_ZERO_PADDING ,$iv);
$decrypted =trim($decrypted);//不加這個解密出來的數據后面會跟亂碼
dd($decrypted);