SHA256

ASP VBScript code for generating a SHA256 ‘digest’ or ‘signature’ of a string.  The SHA256 algorithm is one of the industry standard methods for generating digital signatures.  It is generically known as a digest, digital signature, one-way encryption, hash or checksum algorithm.  A common use for SHA256 is for password encryption as it is one-way in nature, that does not mean that your passwords are not free from a dictionary attack.

if you are using the routine for passwords, you can make it a little more secure by concatenating some known random characters to the password before you generate the signature and on subsequent tests, so even if a hacker knows you are using SHA-256 for your passwords, the random characters will make it harder to dictionary attack.

Due to the way in which the string is processed the routine assumes a single byte character set.  VB passes unicode (2-byte) character strings, the ConvertToWordArray function uses on the first byte for each character.  This has been done this way for ease of use, to make the routine truely portable you could accept a byte array instead, it would then be up to the calling routine to make sure that the byte array is generated from their string in a manner consistent with the string type.

License

This is ‘free’ software with the following restrictions

You may not redistribute this code as a ‘sample’ or ‘demo’.  However, you are free to use the source code in your own code, but you may not claim that you created the sample code.  It is expressly forbidden to sell or profit from this source code other than by the knowledge gained or the enhanced value added by your own code.

Use of this software is also done so at your own risk.  The code is supplied as is without warranty or guarantee of any kind.

Should you wish to commission some derivative work based on this code provided here, or any consultancy work, please do not hesitate to contact us.

About

Summary
ASP VBScript code for generating a SHA256 ‘digest’ or ‘signature’ of a string.
Use this method to encrypt your data.

Functions

encryptData

public function encryptData( sMessage )

Use this method to encrypt your data.

Parameters

(string)sMessage Data to be encrypted

Returns

(string) Encrypted version of the input data

Example

dim message : message = "This is a very secret message"
dim Encryptor
set Encryptor = new SHA256
Response.write("Plain: " & message & "<br />")
Response.write("Encrypted: " & Encryptor.encryptData(message))
set Encryptor = nothing
public function encryptData( sMessage )
Use this method to encrypt your data.