meta
meta copied to clipboard
[Nodejs] AES-SIV: ciphertext verification failure
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)
}
Might've be related to some issues with node-webcrypto-ossl: https://github.com/miscreant/miscreant/pull/155
@tarcieri I haven't included that library. Should I?
If so, how do I make miscreant use it?
Oh sorry, I didn't notice you were using the polyfill profider
@tarcieri Should I try using node-webcrypto-ossl? If so, how to I use that? I can't see any documentation on that.
It should always work with the polyfill provider. I'll have to investigate