JavaScript AES加密和解密(高级加密标准) [英] JavaScript AES encryption and decryption (Advanced Encryption Standard)

查看:163
本文介绍了JavaScript AES加密和解密(高级加密标准)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用JavaScript中的AES(高级加密标准)实现加密和解密。



为何选择AES(高级加密标准)?



安全性:与其他提交的密码相比,竞争算法将根据其抵御攻击的能力来判断,尽管安全强度被认为是竞争中最重要的因素。



成本:拟在全球,非专有和免版税的基础上发布,候选算法将在计算和内存效率。

解决方案

AES是一种非常简单而强大的加密和解密方法。请参阅我的下面的示例,它将很容易在您的现成代码中使用。



只需要调用 encryptMessage decryptMessage fnuction。我已在下面提供了运行示例。



如何调用这些方法:

  code.encryptMessage('欢迎使用AES!','your_password'); 
code.decryptMessage('U2FsdGVkX1 / S5oc9WgsNyZb8TJHsuL7 + p4yArjEpOCYgDTUdkVxkmr + E + NdJmro9','your_password')

< pre class =snippet-code-js lang-js prettyprint-override> let code =(function(){return {encryptMessage:function(messageToencrypt ='',secretkey =''){var encryptedMessage = CryptoJS.AES.encrypt(messageToencrypt,secretkey); return encryptedMessage.toString();},decryptMessage:function(encryptedMessage ='',secretkey =''){var decryptedBytes = CryptoJS.AES.decrypt(encryptedMessage,secretkey); var decryptedMessage = decryptedBytes.toString(CryptoJS.enc.Utf8); return decryptedMessage;}}})(); console.log(code.encryptMessage('Welcome to AES!','your_password')); console.log(code .decryptMessage('U2FsdGVkX1 / S5oc9WgsNyZb8TJHsuL 7 + p4yArjEpOCYgDTUdkVxkmr + E + NdJmro9','your_password'))

 <!DOCTYPE html>< html>< head> <标题> E2EE< /标题> < script src =https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js>< / script>< / head>< body> < / body>< / html>  



你也可以请参阅我的 github 代码库以获取更多参考资料。



https://github.com/shedagemayur/JavaScriptCode/tree/master/AES


How to implement encryption and decryption using AES (Advanced Encryption Standard) in JavaScript.

Why AES (Advanced Encryption Standard) ?

Security: Competing algorithms were to be judged on their ability to resist attack, as compared to other submitted ciphers, though security strength was to be considered the most important factor in the competition.

Cost: Intended to be released under a global, nonexclusive and royalty-free basis, the candidate algorithms were to be evaluated on computational and memory efficiency.

解决方案

AES is very Simple and powerful encryption and decryption method. Please see my below example that will very easy to use in your ready code.

Just need to call encryptMessage and decryptMessage fnuction. I already provided running example below.

How to called these methods:

code.encryptMessage('Welcome to AES !','your_password');
code.decryptMessage('U2FsdGVkX1/S5oc9WgsNyZb8TJHsuL7+p4yArjEpOCYgDTUdkVxkmr+E+NdJmro9','your_password')

let code = (function(){
    return{
      encryptMessage: function(messageToencrypt = '', secretkey = ''){
        var encryptedMessage = CryptoJS.AES.encrypt(messageToencrypt, secretkey);
        return encryptedMessage.toString();
      },
      decryptMessage: function(encryptedMessage = '', secretkey = ''){
        var decryptedBytes = CryptoJS.AES.decrypt(encryptedMessage, secretkey);
        var decryptedMessage = decryptedBytes.toString(CryptoJS.enc.Utf8);

        return decryptedMessage;
      }
    }
})();

console.log(code.encryptMessage('Welcome to AES !','your_password'));
console.log(code.decryptMessage('U2FsdGVkX1/S5oc9WgsNyZb8TJHsuL7+p4yArjEpOCYgDTUdkVxkmr+E+NdJmro9','your_password'))

<!DOCTYPE html>
<html>
<head>
	<title>E2EE</title>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/aes.js"></script>
</head>
<body>

</body>
</html>

You can also refer my github code repository for more references.

https://github.com/shedagemayur/JavaScriptCode/tree/master/AES

这篇关于JavaScript AES加密和解密(高级加密标准)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆