Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在普通javascript aes js加密中将字符串转换为256位数组_Javascript_Html_Node.js_Npm_Aes - Fatal编程技术网

在普通javascript aes js加密中将字符串转换为256位数组

在普通javascript aes js加密中将字符串转换为256位数组,javascript,html,node.js,npm,aes,Javascript,Html,Node.js,Npm,Aes,我使用aes js加密来加密文本。它在硬编码的256位键上运行良好,但我想使用文本键,它应该在转换为256位之前使用。在aes js文档中,有一个建议用于此目的的包,它是pbkdf2,但我使用带html的纯js,不能使用Required js。我找不到该软件包的js文件。有什么解决办法吗?如何将文本转换为256位?附加了加密功能 function encryptit() { // Hard coded key var key_256

我使用aes js加密来加密文本。它在硬编码的256位键上运行良好,但我想使用文本键,它应该在转换为256位之前使用。在aes js文档中,有一个建议用于此目的的包,它是pbkdf2,但我使用带html的纯js,不能使用Required 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();
            }