I'm actually working on a new project based on netsuite product. I'm trying to encrypt a message using hmac sha256.
What's is the simple way to do it considering that I have the stringToEncrypt and a key.
I've read the documentation in Netsuite but I'm still stucked...
There is my function
function toHmacSHA256Base64(toCrypt, key) {
var inputString = toCrypt;
var myGuid = key;
var sKey = crypto.createSecretKey({
guid: myGuid,
encoding: encode.Encoding.UTF_8
});
var hmacSHA256 = crypto.createHmac({
algorithm: 'SHA256',
key: sKey
});
hmacSHA256.update({
input: inputString,
inputEncoding: encode.Encoding.BASE_64
});
var digestSHA256 = hmacSHA256.digest({
outputEncoding: encode.Encoding.HEX
});
return digestSHA256;
};
of course behind the word crypto
I use the module 'N/crypto'
and encode 'N/encode'
.
Thx a lot.