Can't decrypt password using CryptoJS

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 16:48:37

问题


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:


回答1:


To get the decrypted, plaintext password using CryptoJS, you need to use:

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


来源:https://stackoverflow.com/questions/31646564/cant-decrypt-password-using-cryptojs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!