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

_reactNativeAesCrypto.default.pbkdf2 is not a function #60

Open
karanzijm opened this issue Dec 2, 2021 · 2 comments
Open

_reactNativeAesCrypto.default.pbkdf2 is not a function #60

karanzijm opened this issue Dec 2, 2021 · 2 comments

Comments

@karanzijm
Copy link

I'm getting the following error while trying to run the readme example:
[TypeError: _reactNativeAesCrypto.default.pbkdf2 is not a function. (In '_reactNativeAesCrypto.default.pbkdf2(password, salt, cost, length)', '_reactNativeAesCrypto.default.pbkdf2' is undefined)]

Environment
"react-native": "0.64.2"
"react": "17.0.1"
Below is my entire file
import React from 'react';
import {Text} from 'react-native';
import Aes from 'react-native-aes-crypto';

const generateKey = (password, salt, cost, length) =>
Aes.pbkdf2(password, salt, cost, length);

const encryptData = (text, key) => {
return Aes.randomKey(16).then(iv => {
return Aes.encrypt(text, key, iv).then(cipher => ({
cipher,
iv,
}));
});
};

const decryptData = (encryptedData, key) =>
Aes.decrypt(encryptedData.cipher, key, encryptedData.iv);

try {
generateKey('Arnold', 'salt', 5000, 256).then(key => {
console.log('Key:', key);
encryptData('These violent delights have violent ends', key)
.then(({cipher, iv}) => {
console.log('Encrypted:', cipher);

    decryptData({cipher, iv}, key)
      .then(text => {
        console.log('Decrypted:', text);
      })
      .catch(error => {
        console.log(error);
      });

    Aes.hmac256(cipher, key).then(hash => {
      console.log('HMAC', hash);
    });
  })
  .catch(error => {
    console.log(error);
  });

});
} catch (e) {
console.error(e);
}
const Encrypt = () => {
return Hello;
};
export default Encrypt;

@Carbonhell
Copy link

The README seems to be wrong. You're probably trying to import Aes like so:
import Aes from 'react-native-aes-crypto'
The correct way is by using NativeModules.Aes, as shown in the demo, like so: https://github.com/tectiv3/react-native-aes-demo/blob/master/App.js#L25

@kriit24
Copy link

kriit24 commented Nov 8, 2023

Same error here, also after importing NativeModules.Aes

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

3 participants