paulmillr / noble-ciphers

Audited & minimal JS implementation of Salsa20, ChaCha and AES
https://paulmillr.com/noble
MIT License
214 stars 8 forks source link

Decrypting with managedNonce as separate functions produces an error: "Error: invalid polyval tag" #43

Closed TernaryFortress closed 2 weeks ago

TernaryFortress commented 2 weeks ago

I have two functions:

export async function encryptAes(plaintext: Uint8Array, aesKey: Uint8Array): Promise<Uint8Array> {
    const aes = managedNonce(siv)(aesKey)
    return aes.encrypt(plaintext)
}

export async function decryptAesSiv(ciphertext: Uint8Array, aesKey: Uint8Array): Promise<Uint8Array> {
    const aes = managedNonce(siv)(aesKey)
    return aes.decrypt(ciphertext)
}

I run these serverless, and have only one key. However, when I try to decrypt the ciphertext per the documentation, I get:

"Error: invalid polyval tag"

My assumption is that I need to pass additional varriables to managedNonce, however I've not been able to get it to work.

TernaryFortress commented 2 weeks ago

Strangely, I am unable to replicate this locally. It is an error exclusive to the server.

I AM able to replicate the error by entering the wrong key, but the server is using the correct key.

Strange. Will continue investigating

TernaryFortress commented 2 weeks ago

Serialization issue.