Node.js中的AEAD AES-256-GCM
如何使用Node.js解密其他语言加密的数据? 为了描述这个问题,我们用Python编写了一些代码:Node.js中的AEAD AES-256-GCM,node.js,aes-gcm,Node.js,Aes Gcm,如何使用Node.js解密其他语言加密的数据? 为了描述这个问题,我们用Python编写了一些代码: plain_text = 'some data' nonce = 'some nonce string' associated_data = 'some associated data' key = '--- 32 bytes secret key here ---' python中的加密 来自cryptography.hazmat.primitives.ciphers.aead导入AESGC
plain_text = 'some data'
nonce = 'some nonce string'
associated_data = 'some associated data'
key = '--- 32 bytes secret key here ---'
python中的加密
来自cryptography.hazmat.primitives.ciphers.aead导入AESGCM
导入base64
aesgcm=aesgcm(key.encode())
encrypted=aesgcm.encrypt(nonce.encode()、纯文本.encode()、关联数据.encode())
打印(aesgcm.decrypt(nonce.encode(),加密,关联的_data.encode())
密文=base64.b64编码(加密)
在Node.js中解密,我们不需要额外的依赖项
加密模块实现了GCM算法,但概念不同
const crypto=require('crypto'))
加密=缓冲区。从(密文'base64')
let decipher=crypto.createDecipheriv('AES-256-GCM',key,nonce)
解密.setAuthTag(加密的.slice(-16))
解译器setAAD(缓冲区from(关联_数据))
让输出=Buffer.concat([
解密.update(加密的.slice(0,-16)),
破译
])
console.log(output.toString())