Node.js 为什么节点的输出长度为32字节?
这是我的密码:Node.js 为什么节点的输出长度为32字节?,node.js,cryptography,aes,Node.js,Cryptography,Aes,这是我的密码: var crypto = require('crypto') function aese (key) { return crypto.createCipher('aes128', key) } var x1 = crypto.randomBytes(16) var y1 = crypto.randomBytes(16) var a = aese(y1) a.write(x1) a.end() var ct = a.read() console.log(ct.lengt
var crypto = require('crypto')
function aese (key) {
return crypto.createCipher('aes128', key)
}
var x1 = crypto.randomBytes(16)
var y1 = crypto.randomBytes(16)
var a = aese(y1)
a.write(x1)
a.end()
var ct = a.read()
console.log(ct.length); //should be 16 but is 32
这是因为填充增加了至少一个字节,16个字节的输入至少给出了17个输出,由于块大小的原因,填充为32 尝试将加密的字节数减少到15,您将得到16个字节作为输出 另一个选择是
var x1=crypto.randomBytes(16)
变量y1=加密随机字节(16)
var a=aese(y1)
a、 设置自动添加(假);如果让我猜的话,我会说这是静脉注射。对不起,应该是ct
var x1 = crypto.randomBytes(16)
var y1 = crypto.randomBytes(16)
var a = aese(y1)
a.setAutoPadding(false); <--- turn of auto-padding
a.write(x1)
a.end()
var ct = a.read()
console.log(ct.length); <--- gives 16 as output