I need to create HmacSHA256 from a string with a private key... I use react-native-crypto-js but I cant use it's HmacSHA256 method, it keeps getting me "undefined function" error, here is my code:
const signature = CryptoJS.HmacSHA256('simple', '123456789');
const signatureBase = signature.toString(CryptoJS.enc.Base64);
I followed it's document either but still getting same error, if you know another solution or the correct way to use this package please help me. thanks.
I found a work around for react native windows HmacSHA256 Algorithm. I have used 2 packages
Step 1:
npm install --save react-native-hash //install this
import { JSHash, JSHmac, CONSTANTS } from "react-native-hash";
JSHmac("message", "SecretKey", CONSTANTS.HmacAlgorithms.HmacSHA256)
.then(hash => hmac_encoded_str=hash)
.catch(e => console.log(e));
OR
let hmac_encoded_str= await JSHmac(canonical_string, "C6PqJwbyW4",
CONSTANTS.HmacAlgorithms.HmacSHA256)
Step 2:
npm install react-native-crypto-js // install this as well
import CryptoJS from "react-native-crypto-js"
CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(hmac_encoded_str));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With