Skip to content

Crash on Android after upgrading to 0.7.2 🐛 #398

@faljabi

Description

@faljabi

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 (⚠️ your issue might get ignored & closed if you don't try this)

Additional information

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions