-
Notifications
You must be signed in to change notification settings - Fork 105
Closed
Description
What's happening?
The code provided crashed on android when using encrypt or decrypt methods. Reverting to 0.7.1 makes it good again.
Note: it is working fine on iOS.
Reproducible Code
import { Buffer } from 'buffer';
import crypto from 'react-native-quick-crypto';
const encrypt = ({ payload, publicKey }) => {
const secretKey = crypto.randomBytes(16);
const iv = crypto.randomBytes(16);
const cipher = crypto.createCipheriv('aes-128-gcm', secretKey, iv);
const encryptedPayload = Buffer
.concat([cipher.update(payload), cipher.final(), cipher.getAuthTag()])
.toString('base64');
const encryptedSessionKey = crypto.publicEncrypt({
key: publicKey,
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING
}, secretKey);
return {
KEY: encryptedSessionKey.toString('base64'),
IV: iv.toString('base64'),
PAYLOAD: encryptedPayload,
secretKey
};
};
const decrypt = ({ response, secretKey }) => {
const { IV, PAYLOAD } = response;
const decipher = crypto.createDecipheriv('aes-128-gcm', secretKey, Buffer.from(IV, 'base64'));
const encryptedPayload = Buffer.from(PAYLOAD, 'base64');
let decrypted = decipher.update(Buffer.from(encryptedPayload.subarray(0, encryptedPayload.length - 16)));
decrypted = Buffer.concat([decrypted, decipher.final()]);
return JSON.parse(decrypted.toString('utf8'));
};
const getPublicKeyInPEMFormat = key => {
return crypto
.createPublicKey({
key: Buffer.from(key, 'base64'),
format: 'der',
type: 'spki'
})
.export({
type: 'spki',
format: 'pem'
});
};
export { decrypt, encrypt, getPublicKeyInPEMFormat };
Relevant log output
Crashing with no logs.
Device
Android
QuickCrypto Version
0.7.2
Can you reproduce this issue in the QuickCrypto Example app?
I didn't try (
Additional information
- I am using Expo
- I have read the Troubleshooting Guide
- I agree to follow this project's Code of Conduct
- I searched for similar issues in this repository and found none.
TheTrunk
Metadata
Metadata
Assignees
Labels
No labels