How to generate the SHA256 signature using JavaScript? | Adobe Campaign Classic

sha-encryption-adobe-campaign-techonol

Just something that I came across. There was a simple requirement to get the SHA256 representation of an email id.

This can be done using the MemoryBuffer method.

A little background on SHA (Secure Hash Algorithm)

The SHA (Secure Hash Algorithm) is one of a number of cryptographic hash functions. A cryptographic hash is like a signature for a text or a data file. SHA-256algorithm generates an almost-unique, fixed size 256-bit (32-byte) hash. Hash is a one-way function – it cannot be decrypted back.

You can search for its applications online.

In the below example we will be generating the SHA256 signature of email id. This can be applied to any data in adobe campaign.

Also, by simply changing the syntax a little bit we can create different versions of the SHA signature. The other formats are shown below.

1. SHA1
2. SHA224
3. SHA384
4. SHA512

These are all supported by Adobe campaign as per AC documentation.

We have to perform 2 steps for this..

Step 1:

Create a workflow containing a JavaScript activity and an end activity. Use the below code in the JavaScript activity.

//Prajwal Shetty: SHA Converter

//Simple Email Validator: To identify invalid email address in the recipient schema

function validateEmail(emailField){
        
        if (emailField.search("@") == -1) 
        {
            return false;
        }
        return true;
}

//SHA Converter
//To keep the code clean I am not using escape function in the SQL query.
//If you are using this query in production, please use escape function to avoid SQL injection.

var cnx = application.getConnection()
var stmt = cnx.query("select semail,irecipientid from nmsrecipient limit 20")
var memBuf = new MemoryBuffer();

for each (var row in stmt)
  {  
     if(validateEmail(row[0])) 
     {
       memBuf.fromString(row[0], "utf-8");
       logInfo("Email : " + row[0] + " ==> "  + "SHA256 Converted Email:" + memBuf.sha256());
     }
     else {
       logInfo("Invalid Email in recipient schema for recipient id = " +row[1]);
     }
  }

memBuf.dispose()
cnx.dispose()

Step 2:

Run the workflow and go to the audit tab. The SHA signature of the data will be displayed.

If there are any recipients with invalid email id, those will also be filtered out. The customer can then correct those email id and prevent delivery rejection to these recipients.

sha-encryption-adobe-campaign-techonol-1

Hope this helps.

error: Content is protected !!