VirgilSecurity / react-native-virgil-crypto

BSD 3-Clause "New" or "Revised" License
49 stars 17 forks source link

Error: Recipient defined with id is not found within message info during data decryption. #80

Open GibbyBox opened 1 year ago

GibbyBox commented 1 year ago

Hey Team,

We're noticing a small fraction of our users getting this error. These users will always get the following error. The vast majority of our users do not experience this.

Recipient defined with id is not found within message info during data decryption.

We haven't been able to replicate this issue. We use this library to decrypt an encrypted private api key (for a third party integration) sent over the air to the user's device.

Specifically, we first call

const keys = virgilCrypto.generateKeys('SECP256R1');
privateKey = virgilCrypto.exportPrivateKey(keys.privateKey).toString('base64');
publicKey = virgilCrypto.exportPublicKey(keys.publicKey).toString('base64');

then we send the public key up to our api endpoint that's using the nodejs virgil-crypto package and encrypt our api key

import { initCrypto, VirgilCrypto, KeyPairType } from 'virgil-crypto';

// ...

await initCrypto();
const virgilCrypto = new VirgilCrypto({
    /** cSpell:ignore secp */
    defaultKeyPairType: KeyPairType.SECP256R1,
});
return virgilCrypto.encrypt(
    Buffer.from([REDACTED]),
    virgilCrypto.importPublicKey(publicKey),
).toString('base64');

back on the device, we decrypt it as follows. The error gets thrown somewhere here

const key = virgilCrypto.decrypt(encryptedMessage, virgilCrypto.importPrivateKey(privateKey)).toString()

I had tried a retry method that performs this entire sequence again if any error occurred, but this doesn't help the users suffering from this specific issue. What can I do to help this project with resolving this sort of issue?

Scratch-net commented 1 year ago

The only way we could reproduce it is for you to provide a sample key and data set that reproduces the issue:

  1. A private key that cannot decrypt the data (create a random one that reproduces the issue)
  2. Encrypted data for the corresponding public key