Hi everyone,
I am looking for similar function on AC for Crypto library.
So, this piece of code should be adapted/translated to run on AC Classic:
...
const crypto = require('crypto');
sig = crypto.createHmac('sha1', appsecret).update(text).digest('bin');
...
I have found this AC function below but not sure is that good replacement.
Any suggestion?
Regards,
Milan
Solved! Go to Solution.
Hi,
You may use hmac as follow (hmacStr is deprecated):
var appsecret = "SECRET"
var text = "hello"
//var sig = hmacStr(text, appsecret, 'SHA1'); // @deprecated
var mbKey = new MemoryBuffer(); // init memory buffer for the key
mbKey.fromString(appsecret, "utf-8"); // convert from string
var mbSignature = new MemoryBuffer(); // init memory buffer for the signature
mbSignature.fromString(text, "utf-8"); // convert from string
var sig = mbSignature.hmac(mbKey, 'SHA1'); // compute SHA-1 HMAC with key
logInfo('text:', text); // "hello"
logInfo('sig:', sig); // rAqO5eBQ+Z8pPOhAPsaztYNsKxQ=
However, it's not the digest in hexadecimal format as in nodeJS:
To do get the hex hmac, you have to use an external library, like jshashes:
loadLibrary('vendor:jshashes_1.0.8');
var appsecret = "SECRET";
var text = "hello";
var SHA1 = new Hashes.SHA1;
logInfo('SHA1: ' + SHA1.hex_hmac(appsecret, text)); // "SHA1: ac0a8ee5e050f99f293ce8403ec6b3b5836c2b14"
Follow this link to import a js library in adobe campaign.
Best
Florian
Views
Replies
Total Likes
Hi,
You may use hmac as follow (hmacStr is deprecated):
var appsecret = "SECRET"
var text = "hello"
//var sig = hmacStr(text, appsecret, 'SHA1'); // @deprecated
var mbKey = new MemoryBuffer(); // init memory buffer for the key
mbKey.fromString(appsecret, "utf-8"); // convert from string
var mbSignature = new MemoryBuffer(); // init memory buffer for the signature
mbSignature.fromString(text, "utf-8"); // convert from string
var sig = mbSignature.hmac(mbKey, 'SHA1'); // compute SHA-1 HMAC with key
logInfo('text:', text); // "hello"
logInfo('sig:', sig); // rAqO5eBQ+Z8pPOhAPsaztYNsKxQ=
However, it's not the digest in hexadecimal format as in nodeJS:
To do get the hex hmac, you have to use an external library, like jshashes:
loadLibrary('vendor:jshashes_1.0.8');
var appsecret = "SECRET";
var text = "hello";
var SHA1 = new Hashes.SHA1;
logInfo('SHA1: ' + SHA1.hex_hmac(appsecret, text)); // "SHA1: ac0a8ee5e050f99f293ce8403ec6b3b5836c2b14"
Follow this link to import a js library in adobe campaign.
Best
Florian
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies