1

React-Native newbie here running into problems and wondering if I have missed a fundamental step in the installation of packages.

I have been trying to use the react-native-rsa-native package (https://github.com/amitaymolko/react-native-rsa-native)

However I am getting

TypeError: undefined is not an object (evaluating '_reactNativeRsaNative.RSA.generateKeys')

My test code is:

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';

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

export default class App extends React.Component {

  componentWillMount() {
    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
      });
  }

  render() {
    ...
  }
}

The steps followed were:

expo init rsatest --template blank@sdk-31 --yarn
cd rsatest
yarn add react-native-rsa-native
react-native link react-native-rsa-native
yarn start

The react-native-rsa-native package does appear in the node_modules directory however I feel I am missing something.

Any ideas?

Rhys
  • 41
  • 4

3 Answers3

1

One thing that may be relevant is componentWillMount is being deprecated.

https://reactjs.org/docs/react-component.html React docs work as the foundation for react native docs.

Also with componentWillMount() if there is fetch call, with a promise, the promise will not return before component mount, the component will return empty at least once.

I suggest trying componentDidMount()

Hope this helps

Edited for spelling*

  • I've changed componentWillMount to componentDidMount and unfortunately the same error remains :( – Rhys Mar 30 '19 at 09:51
0

That library is not compatible with Expo. Check here why: react native link using expo?

So you might want to expo eject. Which I think is not an option either.

How about you try this one below instead? https://github.com/z-hao-wang/react-native-rsa

Tyro Hunter
  • 755
  • 1
  • 8
  • 20
  • That explains why it wasnt and will not work. I had seen react-native-rsa but went for react-native-rsa-native as it provided sign and verify functionality which i will eventually need. I will keep searching. Many thanks for the answer. – Rhys Mar 30 '19 at 12:06
0

You can delete the node modul and then npm install react-native link react-native run-android/ run-ios

maybe

this helpfull : how to delete installed library form react native project

zidniryi
  • 1,212
  • 3
  • 15
  • 36