meta icon indicating copy to clipboard operation
meta copied to clipboard

[Nodejs] AES-SIV: ciphertext verification failure

Open jeprojects opened this issue 6 years ago • 5 comments

I am using the following, but can't seem to get it working in Node 9. Any help would be appreciated.

Error: AES-SIV: ciphertext verification failure!

let generateDataKey = () => {
    return new Promise((resolve, reject) => {
        crypto.randomBytes(32, (err, buf) => {
            if (err) throw err;
            resolve(buf);
        });
    });
};

let generateNonce = () => {
    return new Promise((resolve, reject) => {
        crypto.randomBytes(16, (err, buf) => {
            if(err) throw err;
            resolve(buf);
        });
    });
};

async function encryptText(plainText) {
    // get new datakey
    const dataKey = await generateDataKey();
    //get nonce
    const nonce = await generateNonce();
    
    // get encryptor
    let encryptor = await miscreant.SIV.importKey(dataKey, "AES-SIV", new miscreant.PolyfillCryptoProvider());
    let stringBuffer = Buffer.from(plainText, 'utf8');
    let cipherText = await encryptor.seal(stringBuffer, dataKey, nonce);
    let decrypted = await encryptor.open(cipherText, nonce)
}

jeprojects avatar Mar 09 '18 16:03 jeprojects

Might've be related to some issues with node-webcrypto-ossl: https://github.com/miscreant/miscreant/pull/155

tarcieri avatar Mar 09 '18 17:03 tarcieri

@tarcieri I haven't included that library. Should I?

If so, how do I make miscreant use it?

jeprojects avatar Mar 09 '18 17:03 jeprojects

Oh sorry, I didn't notice you were using the polyfill profider

tarcieri avatar Mar 09 '18 17:03 tarcieri

@tarcieri Should I try using node-webcrypto-ossl? If so, how to I use that? I can't see any documentation on that.

jeprojects avatar Mar 09 '18 17:03 jeprojects

It should always work with the polyfill provider. I'll have to investigate

tarcieri avatar Mar 09 '18 18:03 tarcieri