amitaymolko / react-native-rsa-native

A native implementation of RSA key generation and encryption/decryption.
MIT License
233 stars 114 forks source link

null is not an object (Evaluating RSA.generateKeys) #80

Open ralucaBoyte opened 4 years ago

ralucaBoyte commented 4 years ago

Do you have an example in Java where you decrypt the message you encrypted with the code below? The key is in PKCS1 format and I can't seem to work this out in Java.

import { RSA } from 'react-native-rsa-native';

let message = "my secret message";

RSA.generateKeys(4096) // set key size
.then(keys => {
    console.log('4096 private:', keys.private); // the private key
    console.log('4096 public:', keys.public); // the public key
    RSA.encrypt(message, keys.public)
    .then(encodedMessage => {
        console.log(`the encoded message is ${encodedMessage}`);
        RSA.decrypt(encodedMessage, keys.private)
        .then(decryptedMessage => {
            console.log(`The original message was ${decryptedMessage}`);
        });
    });
});
Georgge commented 4 years ago

Same error! only in ios

alexanderjeurissen commented 4 years ago

I'm experiencing the same issue when trying to generate keys on IOS.

This is the object that comes back from const Rsa = require('react-native-rsa-native');:

image

I tried downgrading to the version referenced the docs to no avail. I also tried previous versions that seemed to have worked fine in the past, but now don't.

@amitaymolko any thoughts on why those objects are null in IOS ?

amitaymolko commented 4 years ago

Which iOS version? Which RSA Native version? Which React Native version? Also what device are you testing on?

I'll try to recreate

alexanderjeurissen commented 4 years ago

Hi @amitaymolko Thanks for replying on such short notice. See the information you requested below:

Which iOS version?

iOS 13.5.1

Which RSA Native version?

I tested the following versions:

Which React Native version?

I'm using expo, resolved at version 37.0.12. which indicates it's using react-native 0.61.4

Also what device are you testing on?

Testing on an iPhone 11 Pro

I'll try to recreate

Thank you so much !!

amitaymolko commented 4 years ago

not sure if/how this would work with Expo.
I haven't ever worked with it and it doesn't seem to be straight forward.
You can read up some more about it here: https://docs.expo.io/expokit/expokit/#changing-native-dependencies

alexanderjeurissen commented 4 years ago

not sure if/how this would work with Expo. I haven't ever worked with it and it doesn't seem to be straight forward. You can read up some more about it here: https://docs.expo.io/expokit/expokit/#changing-native-dependencies

when reading the docs it does seem that it should be straightforward.

Many libraries in the React Native ecosystem include instructions to run react-native link. These are supported with ExpoKit for iOS. [...]

and

[...] If the library supports CocoaPods (has a .podspec file), just follow the normal instructions and run react-native link.

I don't see mention of the necessity to link react-native link in the README of this project (react-native-rsa-native), however the fact that this project does have a .podspec file should mean that there is no difference with a regular react native stack in this regard.

There are deprecation warnings in the docs you linked however and the “bare workflow” that the documentation links to indicates that “ejecting” from Expo is required. https://docs.expo.io/bare/customizing/

I’ll give ejecting a shot and see if that fixes the issue.

raptox commented 3 years ago

@alexanderjeurissen did u manage to fix this problem? I would like to know if it is possible to use Expo with this library

alexanderjeurissen commented 3 years ago

@raptox I did not. The project I needed this for is currently on the back burner and if I revisit it I'm strongly considering writing it in Swift / Objective C

HPaulson commented 2 years ago

Seems that this still doesn't work on Expo a year later. Unfortunate

fukemy commented 2 years ago

this lib is DEAD

Dror-Bar commented 2 years ago

I thought this happened to me since I saw a (null) popup in console.log. But it might have been unrelated. My app crashed on IOS because the public key I used didn't have -----BEGIN PUBLIC KEY----- and -----END PUBLIC KEY----- surrounding it.