Ask Your Question
2

The outputs of PHP's openssl_encrypt and Javascript's crypto.subtle.encrypt for AES-256-GCM differ, can you explain why?

asked 2022-07-16 11:00:00 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2022-11-14 09:00:00 +0000

qstack gravatar image

There are several potential reasons why the output of PHP's openssl_encrypt and Javascript's crypto.subtle.encrypt for AES-256-GCM encryption may differ, including:

  1. Key derivation: Both PHP's openssl_encrypt and Javascript's crypto.subtle.encrypt require a key to encrypt and decrypt data. If the key is derived differently in both languages, it could result in different ciphertext outputs. It is also possible that the key was not properly converted between the two languages, leading to differences in the encrypted output.

  2. Padding: Padding is used to ensure that the data to be encrypted is of the correct length. If the padding scheme used in PHP and Javascript differ, this could also result in different ciphertext outputs.

  3. Initialization Vector (IV): AES-GCM encryption requires a unique initialization vector (IV) for each encryption operation. If the IV used in PHP and Javascript differ, it could also result in different ciphertext outputs.

  4. Endianess: Endianess refers to the way in which data is ordered in memory. If the byte order of the data being encrypted or decrypted differs between PHP and Javascript, it could also result in different ciphertext outputs.

Overall, it is important to ensure that the encryption and decryption processes are consistent between PHP and Javascript, including key derivation, padding, IV generation, and endianess.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-07-16 11:00:00 +0000

Seen: 15 times

Last updated: Nov 14 '22