node.js - 为什么node的aes-256-gcm能产生长度不能被16整除的密文?
问题描述
尽管 AES-256-GCM 使用块大小为 16 字节的块 chiffre,但为什么以下 nodejs 代码会产生总长度不能被 16 整除的输出?
const crypto = require('crypto')
let iv = Buffer.from('ed655ce15162cecc9a0fc47fbc5055e2', 'hex')
let key = Buffer.from('17c0c95f4499dc8cb2b11d8c68569729484579df9adeceb7898fd9508915e46f', 'hex')
let cipher = crypto.createCipheriv('aes-256-gcm', key, iv)
let outputA = cipher.update("some string", 'utf8')
let outputB = cipher.final()
console.log(outputA.length, outputB.length) //output: "11 0"
//outputA = <Buffer 26 5b 11 63 cf 26 44 81 d2 1d 77>
解决方案
显然 GCM 不需要填充,也不需要明文是块大小的倍数。
更多信息在这里。
推荐阅读
- c# - 等待作为参数传递给方法的类实例的结果
- javascript - 与使用 angular 生成动态表单相关的必要建议
- ms-word - 无法自动编号 word doc 中的数字
- javascript - 如何在 Chrome 70 的 Javascript 控制台中禁用自动完成功能?
- c# - c#: string(json) 到 object(generic) 的转换添加了额外的大括号
- ios - 对成员 'collectionView' Swift 4 的模棱两可的引用
- python - Django Model ImageField upload_to 不会将函数作为参数
- python - 如何矢量化 for 循环?
- c# - 使用 MVVM 在 WPF DataGrid CellEditEnding 事件中取消后将光标保留在单元格中
- c++ - -fno-inline 和编译时间