前端crypto-js加密,后台php解密

crypto-js加密

function onSubmit()
{
    var userObj = $('#username');
    var pwdObj = $('#password');
    var text = JSON.stringify({user:userObj.val(),pwd:pwdObj.val()});
    var key = CryptoJS.enc.Latin1.parse('1234567887654321'); //为了避免补位,直接用16位的秘钥
    var iv = CryptoJS.enc.Latin1.parse('1234567887654321'); //16位初始向量
    var encrypted = CryptoJS.AES.encrypt(text, key, {
        iv: iv,
        mode:CryptoJS.mode.CBC,
        padding:CryptoJS.pad.ZeroPadding
    }).toString();
    userObj.remove();pwdObj.remove();
    $('#postData').val(encrypted);
}

php解密

//解密
$key = "1234567887654321";
$iv = "1234567887654321";
$decrypted = openssl_decrypt(($map['postData']), 'aes-128-cbc', $key, OPENSSL_ZERO_PADDING, $iv);
$decrypted = json_decode(trim($decrypted),true);    

你可能感兴趣的:(前端crypto-js加密,后台php解密)