I read a post: encrypted-data-between-node-js-and-python.
I need to implement the reverse path, create the encryption in python and decode in the node.
On the Python side I did:
from nacl.secret import SecretBox
from base64 import b64encode
import nacl.secret
import nacl.utils
secret_key = bytes('_THIS_IS_MY_32_CHARS_SECRET_KEY_', 'utf8')
message = bytes('Some Italians hate wine','utf-8')
nonce = nacl.utils.random(24)
box = SecretBox(secret_key)
encrypted = box.encrypt(message,nonce)
ctext = encrypted.ciphertext
print(ctext)
plaintext = box.decrypt(encrypted)
print(plaintext.decode('utf-8'))
print(b64encode(nonce))
print(b64encode(encrypted
In node:
const nacl = require('tweetnacl');
const utils = require('tweetnacl-util');
const secretKey = Buffer.from('_THIS_IS_MY_32_CHARS_SECRET_KEY_', 'utf8');
const nonce = utils.decodeBase64('KRmiqOFUN1HklmPZgbd0BINNDDCu3dyB');
const encryptedMessage = utils.decodeBase64('KRmiqOFUN1HklmPZgbd0BINNDDCu3dyB/s4tdTjcw65K6Lr5N797+7zoLm9WClCXIDNLAqrNGwF2MybtJu+U');
const originalMessage = nacl.secretbox.open(
encryptedMessage,
nonce,
secretKey
);
The result was NULL.
What is the correct way to do this integration?