I have added cryptojs and requirejs scripts to my project settings > code section but are unable to call their functions:
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/crypto-js.min.js"></script>
For example I need to create a md5 hash signature for a header of a GET request for a payment gateway, when I call the function it results in undefined function:
//this line results in cryptoJS is not defined
return cryptoJS.createHash(“md5”).update(getString).digest(“hex”);
const cryptoJS = require([crypto]);
const generateSignature = (data, passPhrase = null) => {
// Create parameter string
let pfOutput = “”;
for (let key in data) {
if(data.hasOwnProperty(key)){
if (data[key] !== “”) {
pfOutput +=${key}=${encodeURIComponent(data[key].trim()).replace(/%20/g, " + ")}&
}
}
}// Remove last ampersand
let getString = pfOutput.slice(0, -1);
if (passPhrase !== null) {
getString +=&passphrase=${encodeURIComponent(passPhrase.trim()).replace(/%20/g, "+")}
;
}return cryptoJS.createHash(“md5”).update(getString).digest(“hex”);
};myData.signature = generateSignature(myData);
Any help will be appreciated. Thanks