Is it possible to do this with Ampscript? Is it possible to achieve this with SSJS?

I understand there is an apex function that can do this, but I am not sure it is possible to use apex with marketing cloud.


I've decided to use SSJS. I have the following:

    <script runat=server>
        Platform.Load("Core", "1");
            var _msg = Variable.GetValue("@message");
            var _secret = Variable.GetValue("@secret");
            var _hashed = CryptoJS.HmacSHA1(_msg, _secret);
            Variable.SetValue("@hashed", _hashed);

However I get an error, Exception of type 'Jint.Native.JsException' was thrown.

It breaks at the var _hashed... line, where CryptoJS is called. I've included the appropriate script sources for this functionality and have tested it on front end JS. However, I cannot seem to get it working on SSJS. Any help would be much appreciated.


It's not possible to use Apex directly in Marketing Cloud, you would have to use either AMPscript or SSJS.

AMPscript has a SHA1 function but not for HMAC.

Potentially what you could do is build an Apex endpoint to handle the hashing and return a response to MC.

If you go this road I find SSJS Post function can better handle the JSON responses.

| improve this answer | |
  • Can you please look at my edit? – legoMyEgo Sep 27 '18 at 17:45
  • @legoMyEgo CryptoJS is a javascript library. the library isn't available on the Marketing Cloud servers you need to setup that library on your own server. (which is why it works front-end) I actually use that library with a cloud function in Azure that accepts an input and returns a hash response however you could use the same method with an Apex endpoint. – Travis Naughton Sep 27 '18 at 22:34
  • The problem I am currently encountering is I am trying to load the CryptoJS library on the server because otherwise MC wont know of the CryptoJS library because the page hasnt loaded yet. I've tried to upload the library in My Contents and loaded it with var CryptoContent = ContentArea(123456);. I tried both ways, first I changed the content area I created to have <script runat=server>` and then I tried it without runat=server. Obviously the latter doesnt work because it's the same issue -- MC doesnt know what it writes to the page because it hasnt loaded yet as far as its concerned. – legoMyEgo Sep 28 '18 at 13:05
  • You can't load the external library on the Marketing Cloud server. If you want to use that library you will have to set it up on your own server. – Travis Naughton Oct 1 '18 at 23:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.