Search code examples
reactjscreate-react-appcryptojs

Using crypto-js in React


I generated an app using create-react-app and I want to use crypto-js I am getting the following error

crypto.sha256() is not a function


Solution

  • You gotta install crypto-js using

    npm install crypto-js
    

    In your js files, you have to import module you wanna use

    import sha256 from 'crypto-js/sha256';
    

    Now you can use those functions

    sha256(nonce + message);
    

    You have do define message and nonce before this