我正在尝试做一些看似简单的事情:
var token = crypto.randomBytes(32);
var wstream = fs.createWriteStream('output.hex');
wstream.write(token);
wstream.end();
运行此代码后,该output.hex
文件为空。token
在代码期间也永远不会修改。
同样,我试试这个:
// encrypts a message
var token = crypto.randomBytes(32);
var cipher = crypto.createCipher('aes-256-cbc', token);
var enc_msg = cipher.update(msg, 'binary', 'binary');
enc_msg += cipher.final('binary');
// print it
console.log(enc_msg); // prints Øôâ¨7"ªðqâ~è (binary data - good)
// check the type
console.log(type of enc_msg); // prints 'string'
// write it to a file (fails)
var wstream = fs.createWriteStream('output.hex');
wstream.write(enc_msg);
wstream.end();
我在这里想念什么?该文件始终是完全空的。