tectiv3 / react-native-aes

Native module for AES encryption
MIT License
187 stars 131 forks source link

_reactNativeAesCrypto.default.pbkdf2 is not a function #60

Open karanzijm opened 2 years ago

karanzijm commented 2 years ago

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 commented 2 years ago

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 commented 10 months ago

Same error here, also after importing NativeModules.Aes