问题描述
我做错了什么?它是 Node.js 16.1.0。
> crypto.createCipheriv("AES-128-CTR",Buffer.allocUnsafe(16),Buffer.allocUnsafe(16));
Cipheriv {…}
> crypto.createCipheriv("AES-128-OCB",Buffer.allocUnsafe(16));
Uncaught TypeError: Invalid initialization vector
at Cipheriv.createCipherBase (node:internal/crypto/cipher:119:19)
at Cipheriv.createCipherWithIV (node:internal/crypto/cipher:138:3)
at new Cipheriv (node:internal/crypto/cipher:246:3)
at Object.createCipheriv (node:crypto:131:10) {
code: 'ERR_CRYPTO_INVALID_IV'
}
解决方法
OCB 模式的初始向量应该是 12 个八位字节; 96 位,即。