AES加密后的文件如何部分解密?
如果整个文件加解密我知道怎么做。如下所示。但是现在需求是只解密部分的文件。比如1G的文件只解密最后1M。请问怎么做?
加密算法现在用的是AES-256-CTR
var crypto = require('crypto');
var fs = require('fs-extra');
var encrypt = crypto.createCipher('AES-256-CTR', 'segmentfault');
var decrypt = crypto.createDecipher('AES-256-CTR', 'segmentfault');
var encryptName = 'encrypt.txt';
var decryptName = 'decrypt.txt';
fs.createReadStream('decrypt.js').pipe(encrypt).pipe(fs.createWriteStream(encryptName)).on('finish', () => {
fs.createReadStream(encryptName).pipe(decrypt).pipe(fs.createWriteStream(decryptName));
});
Problem solved.
Use this module https://npm.taobao.org/packag...
Why don’t you encrypt in segments when encrypting... Then you can decrypt in segments when decrypting?