输入错误密码时显示通知框以解锁由Cryptojs加密的内容

时间:2018-05-14 08:38:58

标签: encryption cryptojs

我使用Cryptojs来加密我的文本,并使用下面的代码来解密:

 <div id="decrypt-box">
 <div class="decrypt-form" id="decryption" data-href="U2FsdGVkX1+Fg5XynZFlZHmhvMhAw9l7jlKt2WEpYYWEkOy7L360rZ7xd19TvoXp">
<div> password to unlock: asd</div>
 <form action="#" id="decrypt-form" method="post">
<input autofocus="" id="decrypt-password" name="password" placeholder="Password" type="password" />

        <input class="decrypt-button" type="submit" value="Unlock" />
    </form>
<div id="decrypt-alert">
</div>
</div>
</div>
<div id='decrypt-content'></div>
<script src="https://cdn.rawgit.com/CryptoStore/crypto-js/3.1.2/build/rollups/aes.js"></script>
<script>
document.getElementById('decrypt-form').addEventListener('submit', function(e) {
    e.preventDefault();
var c=document.getElementById('decryption');
    var encryptedMsg=c.getAttribute('data-href'),
        passphrase = document.getElementById('decrypt-password').value,
        decrypted = CryptoJS.AES.decrypt(encryptedMsg, passphrase);
        decrypted = decrypted.toString(CryptoJS.enc.Utf8);                                    

        document.getElementById('decrypt-content').innerHTML = decrypted;    

});
</script>

我的问题是:

如果输入错误密码,如何显示通知框。

感谢。

0 个答案:

没有答案