Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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.