PHP7与CryptoJS的AES加密的方式互通代码



前端代码:

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

你可能感兴趣的:(PHP7与CryptoJS的AES加密的方式互通代码)