Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error generating encryption key: [TypeError: Cannot read property 'pbkdf2' of null] #89

Open
shubh-neorox opened this issue Aug 13, 2024 · 7 comments

Comments

@shubh-neorox
Copy link

in IOS I am able to genrate key by using this way
import Aes from "react-native-aes-crypto";
const generateKey = async (password, salt, cost, length) => Aes.pbkdf2(password, salt, cost, length, "sha256");

but in android I am unable to get it 
getting this error :"Error generating encryption key: [TypeError: Cannot read property 'pbkdf2' of null]"

react native version :0.74
@Jonnynsk
Copy link

Jonnynsk commented Sep 24, 2024

in IOS I am able to genrate key by using this way import Aes from "react-native-aes-crypto"; const generateKey = async (password, salt, cost, length) => Aes.pbkdf2(password, salt, cost, length, "sha256");

but in android I am unable to get it 
getting this error :"Error generating encryption key: [TypeError: Cannot read property 'pbkdf2' of null]"

react native version :0.74

Did you add
include ':react-native-aes-crypto'
project(':react-native-aes-crypto').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-aes-crypto/android')
in android/settings.gradle ?

And
dependencies {
implementation project(':react-native-aes-crypto')
}
in android/app/build.gradle ?

@shubh-neorox
Copy link
Author

implementation project(':react-native-aes-crypto')

Yes i did already still the same issue

@tectiv3
Copy link
Owner

tectiv3 commented Dec 6, 2024

Are you still having issues after upgrading to 3.1?

https://github.com/tectiv3/react-native-aes-demo

@shubh-neorox
Copy link
Author

shubh-neorox commented Dec 6, 2024 via email

@jplandry908
Copy link

I came across this issue searching for a solution for a similar error. It appears 'Aes' is null.

Simple example:
import Aes from 'react-native-aes-crypto';

try {
console.log('init');
console.log(Aes);
const test1 = Aes.randomUuid();
console.log(test1);
} catch (error) {
console.log(error);
}

LOG init
LOG null
LOG [TypeError: null is not an object (evaluating '_reactNativeAesCrypto.default.randomUuid')]

I am on react-native 0.76 and was able to test the DEMO without any issues. However, I noticed that I have the new architecture disabled (since a couple of the modules I am using doesn't fully support it yet). If you add this line to POD file in your DEMO (disabling the new architecture), you can reproduce this issue and the DEMO also fails.

ENV['RCT_NEW_ARCH_ENABLED'] = '0'

@jplandry908
Copy link

jplandry908 commented Dec 9, 2024

@tectiv3 - FYI

This may not be the best solution, but I found a fix/workaround to my issue after reading through a bunch of react-native new architecture blogs and others complaining about Native Modules being null.

Below is a patch outlining the change I made. I basically had to call out each function in the 'index.js' file, and also change it from 'RTCAes' to just 'Aes.'. However, this breaks Android, so I added a Platform.OS check as well.

Note: This is the comment that had my try this approach ...
facebook/react-native#29228 (comment)

diff --git a/node_modules/react-native-aes-crypto/index.js b/node_modules/react-native-aes-crypto/index.js
index cb179dc..8f22f4d 100755
--- a/node_modules/react-native-aes-crypto/index.js
+++ b/node_modules/react-native-aes-crypto/index.js
@@ -1,4 +1,22 @@
 'use strict'
-import { NativeModules } from 'react-native'
+import { NativeModules, Platform } from 'react-native'
 
-export default NativeModules.RCTAes
+const AES =
+  Platform.OS === 'ios'
+    ? {
+        randomKey: NativeModules.Aes.randomKey,
+        pbkdf2: NativeModules.Aes.pbkdf2,
+        pbkdf2Sync: NativeModules.Aes.pbkdf2Sync,
+        encrypt: NativeModules.Aes.encrypt,
+        decrypt: NativeModules.Aes.decrypt,
+        hmac256: NativeModules.Aes.hmac256,
+        hmac512: NativeModules.Aes.hmac512,
+        randomKey: NativeModules.Aes.randomKey,
+        randomUuid: NativeModules.Aes.randomUuid,
+        sha1: NativeModules.Aes.sha1,
+        sha256: NativeModules.Aes.sha256,
+        sha512: NativeModules.Aes.sha512,
+      }
+    : NativeModules.RCTAes;
+
+export default AES
\ No newline at end of file

@tectiv3
Copy link
Owner

tectiv3 commented Dec 18, 2024

I've renamed the package again, making the naming more consistent. Replaced all RCTAes with Aes.

https://github.com/tectiv3/react-native-aes-demo

Screenshot 2024-12-18 at 8 39 34 Screenshot 2024-12-18 at 8 40 30

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants