简体   繁体   中英

Can't decrypt password using CryptoJS

I am trying to make an encryption using CryptoJS. The encryption seems to work fine, but when I decrypt the password, I do not get the initial plain text password.

Here is my JavaScript code:

<script type="text/javascript">
var password = "";
function noSsl()
{
    $(document).ready(function()
    {
        $("#dialog").dialog({ show: 'fade', hide: 'fade' });
    });
}
function savePassword()
{
    password = document.getElementById("ap").value;
    alert("Initial password: " + password);
    enPassword = CryptoJS.AES.encrypt(password, <?php echo '"'.$currentAdk.'"'; ?>);
    $(document).ready(function()
    {
        $("#ap").slideToggle("slow");
        $("#sp").slideToggle("slow");
        $("#sp").remove();
    });
    alert("Encrypted: " + enPassword);
    var decrypted = CryptoJS.AES.decrypt(enPassword, <?php echo '"'.$currentAdk.'"'; ?>)
    alert("Decrypted: " + decrypted);
}
</script>

Here are the results:

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

要使用 CryptoJS 获取解密的明文密码,您需要使用:

var decryptedPlaintextPassword = CryptoJS.AES.decrypt(enPassword, <?php echo '"'.$currentAdk.'"'; ?>).toString(CryptoJS.enc.Utf8);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM