5/16/14

SHA256 and classic ASP VBSCRIPT for intercom.io secure settings and others

I've recently been using intercom.io to manage my member communication and they require a secure mode to be enabled that passes a hashed value with each session.

On the back end I needed to create javascript that looked like this:


The user hash needed to be a SHA256 hash of the users email address and the unique "salt" or secret key provided by intercom.io on a user account basis.

The problem was that I'm using Vbscript/classic ASP so was having trouble sorting this out with the limited VBScript library.

The solution was found courtesy of:

/*
 * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
 * in FIPS 180-2
 * Version 2.2 Copyright Angel Marin, Paul Johnston 2000 - 2009.
 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
 * Distributed under the BSD License
 * See http://pajhome.org.uk/crypt/md5 for details.
 * Adapted into a WSC for use in classic ASP by Daniel O'Malley
 * (based on an SHA-1 example by Erik Oosterwaal)
 * for use with the Amazon Product Advertising API
 */

Basically you create a stand alone file called sha256.wsc that lives in the same directory as the function - then pass in the appropriate variables.

VBScript Function:

The contents for sha256.wsc follow at the end of the post. Good luck and happy coding