1
$\begingroup$

I have a cookie being encrypted with AES-256-GCM in Rust using ring. I need to decrypt the cookie in Node.js. I'm using the standard crypto library, but it's just not working.

My understanding is that different implementations of AES-256-GCM algorithm should be compatible as long as they

  1. Use the same key
  2. Use the same ADD, and
  3. Use the same IV/nonce. (Node.js calls it IV, ring calls it nonce.)

Is this correct?

I just want to double-check before spending even more time on this.

$\endgroup$
2
$\begingroup$

Yes.

HOWEVER....

An implementation may put the content of the encrypted message wherever it wants, and format the encrypted message any way it wants, including different text encodings such as Base64

You will need to take that into account, when decrypting the message, the input must be formatted in the way that an implementation is expecting, and that may be very different than what you have, or that a different implementation may output.

There may also be other things which are not part of the message, such as the expected size of the auth tag or nonce, but all implementations following the spec will deal with variations in size correctly, as long as they are told to do so.

For example, implementation A may output the data in this way [nonce][message][tag], and it may expect 3 inputs for decryption, output data stream, auth data, and key, then extract the nonce and tag from the message automatically, since that implementation only uses 96-bit nonce and tag sizes.

Implementation B may output the message, tag, auth data, and nonce as a Base64 formatted strings inside an XML file, and only take the same XML file and the key as inputs, and will detect the size of the nonce and tags from their specified lengths in the file, decode from B64, and decrypt the message.

As long as you can translate the encoding from one to another, you should be able to make them compatible. The dev documentation of those projects should show what output format they use, and if there are runtime options to modify that format.

$\endgroup$
  • $\begingroup$ As seen from the questions from SO, there is no plug and play. Also. some may provide many different key derivation functions from passwords, these match. Also, the encoding of the password is important. $\endgroup$ – kelalaka Nov 15 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.