crypto进行DES加密的问题Invalid IV length错误
发布于 6 年前 作者 entrehuihui 7292 次浏览 来自 问答

// DES 加密 encrypt(value, key, iv = 0) { key = new Buffer(key); iv = new Buffer(iv ? iv : 0); const cipher = crypto.createCipheriv(“des-ecb”, key, iv); cipher.setAutoPadding(true); let ciph = cipher.update(value, “utf8”, “base64”); ciph += cipher.final(“base64”); return ciph; },

const DES_key = “qwertyuioppoiuytrewqasdf”; const IV = 19283746; const value= new Date().getTime(); 改怎么转换调用DES加密 直接调用一直是Invalid IV length 错误

1 回复

iv的确是有长度限制的,根据算法采用位数不同会有一些区别,应该是8个比特辣么长 你的iv 可以这样 crypto.randomBytes(8) 取一下

回到顶部