Node.js 如何在npm中的wards之后解密

Node.js 如何在npm中的wards之后解密,node.js,encryption,sha,Node.js,Encryption,Sha,我有来自nodejs.org的文件加密示例 const fs = require('fs'); const algorithm = 'aes-192-cbc'; const password = 'Password used to generate key'; // Use the async `crypto.scrypt()` instead. const key = crypto.scryptSync(password, 'salt', 24); // Use `crypto.random

我有来自nodejs.org的文件加密示例

const fs = require('fs');

const algorithm = 'aes-192-cbc';
const password = 'Password used to generate key';
// Use the async `crypto.scrypt()` instead.
const key = crypto.scryptSync(password, 'salt', 24);
// Use `crypto.randomBytes()` to generate a random iv instead of the static iv
// shown here.
const iv = Buffer.alloc(16, 0); // Initialization vector.

const cipher = crypto.createCipheriv(algorithm, key, iv);

const input = fs.createReadStream('test.js');
const output = fs.createWriteStream('test.enc');

input.pipe(cipher).pipe(output);
}
如何使用同一个密钥访问oposite并让test.enc测试.js


提前感谢

您可以使用类似的过程对使用上述代码加密的文件进行解密

我们将把解密后的文件写入“testdecoded.js”,这样就不会覆盖原始文件

我还想指出,理想情况下,您应该使用一个随机值填充IV,并将其与加密数据一起存储,尽管如果您只是在测试,它实际上并不重要

const fs = require('fs');
const crypto = require("crypto");

const algorithm = 'aes-192-cbc';
const password = 'Password used to generate key';
const key = crypto.scryptSync(password, 'salt', 24);
const iv = Buffer.alloc(16, 0); // Initialization vector.

const decryptInput = fs.createReadStream('test.enc');
const decryptOutput = fs.createWriteStream('test-decoded.js');
const decipher = crypto.createDecipheriv(algorithm, key, iv);
decryptInput.pipe(decipher).pipe(decryptOutput);

您可以使用类似的过程来解密使用上述代码加密的文件

我们将把解密后的文件写入“testdecoded.js”,这样就不会覆盖原始文件

我还想指出,理想情况下,您应该使用一个随机值填充IV,并将其与加密数据一起存储,尽管如果您只是在测试,它实际上并不重要

const fs = require('fs');
const crypto = require("crypto");

const algorithm = 'aes-192-cbc';
const password = 'Password used to generate key';
const key = crypto.scryptSync(password, 'salt', 24);
const iv = Buffer.alloc(16, 0); // Initialization vector.

const decryptInput = fs.createReadStream('test.enc');
const decryptOutput = fs.createWriteStream('test-decoded.js');
const decipher = crypto.createDecipheriv(algorithm, key, iv);
decryptInput.pipe(decipher).pipe(decryptOutput);

我将用一个问题来回答你的问题。在文档中,直接在
crypto.createCipheriv()之后的方法是什么?
?我将用一个问题回答您的问题。在文档中,直接位于
crypto.createCipheriv()之后的方法是什么?