Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js中的AEAD AES-256-GCM_Node.js_Aes Gcm - Fatal编程技术网

Node.js中的AEAD AES-256-GCM

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

如何使用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导入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())