Dec 13th, 2010, 08:17 AM
[VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
HS256, a class for calculating HMAC-SHA-256 from a Key and Data in VB6.
HS1 (HMAC-SHA-1) also included now. Scroll down to the latest versions of both!
The HS256 class uses Windows Crypto API calls wherever possible to calculate HMACs (Hash-based Message Authentication Codes) based on SHA 256 hashes. The class also provides formatting functions between binary data and Strings (Base64, Hex, and Hex variations) as well as converting Strings to and from UTF8 encoding.
All of these things are useful in creating message authentication strings for many purposes. These HMACs are needed in message authentication for the SOAP and REST APIs provided by many cloud computing services. They are also sometimes used to sign other types of messages (e.g. email).
- HMAC-SHA-256 calculation without the use of any external cryptography components, relies on the Windows Crypto API.
- Translation of binary data to and from Base64 strings.
- Translation of binary data to and from Hex strings (several variations such as Hex with address and ASCII).
- Translation of standard "Unicode" (UTF16-LE) String data to and from UTF8 encoding.
Screenshot of the (attached) demo shown below.
Requires Windows XP or later. May require XP SP1 or SP2 (Crypto API documentation is not explicit on this point). Some minor format variations are emulated under Windows XP instead being performed via Crypto API calls, one minor sub-variation is only available in Windows 2003 R2, Vista, or later.
No special processor, disk, or memory requirements. Requires Visual Basic 6.0 development system, preferably Service Pack 6b or later, Standard Edition or better.
This software is released into the Public Domain. It may be used for any purpose as is or in derivative works. No warranty of fitness or merchantability, and no support is offered. This source code is available AS IS.
Add the class module to your VB6 project. See comments at the head of the source regarding use of the methods and properties provided.
The demonstration project
The HS256 class is posted here as part of a demo program.
This program demonstrates the 7 SHA-256 Test Case vector sets found in RFC 4231:
Identifiers and Test Vectors for HMAC-SHA-224, HMAC-SHA-256,
HMAC-SHA-384, and HMAC-SHA-512
Last edited by dilettante; Apr 16th, 2011 at 10:00 PM.
Click Here to Expand Forum to Full Width
Survey posted by VBForums.