如何解决将字符串转换为纯javascript aes-js加密的256位数组
我正在使用aes-js加密来加密文本。它在硬编码的256位密钥上工作正常,但我想改用文本密钥,该密钥应在之前转换为256位。在aes-js文档中,建议为此使用pbkdf2的软件包,但我将html与普通js结合使用,因此无法使用require js。我找不到该程序包的js文件。有什么解决办法吗?如何将文本转换为256位?附有加密功能
function encryptit() {
// Hard coded key
var key_256_bit = [
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,];
var plaintext = document.getElementById("plaintext").value;
//this is the key I want to use
var key = document.getElementById("key").value;
var plaintextBytes = aesjs.utils.utf8.toBytes(plaintext);
// The counter is optional,and if omitted will begin at 1
var aesCtr = new aesjs.ModeOfOperation.ctr(
key_256_bit,new aesjs.Counter(5)
);
var encryptedBytes = aesCtr.encrypt(plaintextBytes);
// To print or store the binary data,you may convert it to hex
var encryptedHex = aesjs.utils.hex.fromBytes(encryptedBytes);
console.log(encryptedHex);
document.getElementById(
"encryptedresult"
).innerHTML = encryptedHex.toString();
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。