2

I followed former answers from Webcrypto AES-CBC Decrypt: Operation Error - The operation failed for an operation-specific reason and JavaScript AES encryption and decryption (Advanced Encryption Standard) and used:

iv = crypto.getRandomValues(new Uint8Array(16))
key = window.crypto.subtle.generateKey(
            {
                name: "AES-GCM",
                length: 256,
            },
            false,
            ["encrypt", "decrypt"]
        )

to generate the key and

Uint8ArrayEncrypted = window.crypto.subtle.encrypt(
        {name: "aes-gcm", iv: iv, tagLength: 128}, 
        key,
        Uint8ArrayVar)

to encrypt and

Uint8ArrayDecrypted = window.crypto.subtle.decrypt(
        {name: "aes-gcm", iv: iv, tagLength: 128}, 
        key,
        Uint8ArrayEncrypted)

to decrypt

On Chromium 83 (Ubuntu) and Firefox 88, I successfully generate the key, the iv and encrypt. And on Chromium, it simply also decrypts without problem.Uint8ArrayDecrypted is correct ArrayBuffer.

But FF throws the error "The operation failed for an operation-specific reason" and stop there. No Uint8ArrayDecrypted returned.

I didn't use tag, like in WebCrypto API: DOMException: The provided data is too small

Reading https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/encrypt, I don't see it uses tag.

Does Firefox need something else specific?

Why the error message is so "generic"? Which operation or specific reason? With an error so generic, I don't know where to look.

phm
  • 23
  • 3
  • Runs fine on my machine under Chromium v85, Chrome v90 and Firefox v88. Post the complete script and not just fragments. Probably you make the mistake somewhere else. – Topaco Apr 28 '21 at 14:05

0 Answers0