var path = require('path');
var fs = require('fs');
var crypto = require('crypto');
var algorithm = 'aes-256-ctr';
var password = 'xxxxx';
var dir = '/Users/antkong/some/path';
var file = 'somefile.json';
var clearTextPath = path.join(dir, file);
var cipher = crypto.createCipheriv(algorithm, password);
var readStream = fs.createReadStream(clearTextPath);
var writeStream = fs.createWriteStream(path.join(dir, file + '.encrypted'));
readStream.pipe(cipher).pipe(writeStream);
然后我得到了这个错误:
internal/crypto/cipher.js:139
this._handle.initiv(cipher, toBuf(key), toBuf(iv));
^
TypeError: IV must be a buffer
at new Cipheriv (internal/crypto/cipher.js:139:16)
at Object.createCipheriv (crypto.js:98:10)
我的节点版本是 9.11.1
我已经验证源文件存在。
为什么失败了?它在旧版本的节点中工作(早于版本 8.x)