Call now: (800) 766-1884  


 SQL Server Tips
 SQL Server Training

 SQL Server Consulting
 SQL Server Support
 SQL Server Remote DBA

 SQL Server Scripts
 Scripts Menu




  SQL Server Tips by Gama and Naughter

MS CryptoAPI based HMAC Implementations

The HMAC implementation is quite similar to the hashing implementation. We first acquire the CSP as per normal. We then create a session key as if we were doing symmetric encryption, using the “CryptCreateHash”, “CryptHashData” and “CryptDeriveKey” functions. Because we must specify the symmetric encryption algorithm to use to create the session key, rather than providing one XP for each Hash / Encryption algorithm pair, we instead specify the encryption algorithm via a parameter to each HMAC XP. The available values for this “SessionKeyAlgorithm” parameter are 26114 for RC2, 26625 for RC4, 26113 for DES, 26121 for 3DES112 and 26115 for 3DES. These values correspond to the actual “Algorithm Identifiers” used by the CryptoAPI. Having created the session key, we next create the actual HMAC hash object using the “CryptCreateHash” function, specifying an algorithm identifier of “CALG_HMAC”. We then specify the type of HMAC to generate by calling the “CryptSetHashParam” function using a. “HMAC_INFO” structure. We then hash the data and return the data as an output parameter similar to the standard hash XP’s. Similar to hashing; we return the data as binary data or a BCD string depending on the output parameter’s data type.

The above book excerpt is from:

Super SQL Server Systems
Turbocharge Database Performance with C++ External Procedures

ISBN: 0-9761573-2-2
Joseph Gama, P. J. Naughter  


Burleson Consulting Remote DB Administration







Burleson is the America's Team

Note: The pages on this site were created as a support and training reference for use by our staff of DBA consultants.  If you find it confusing, please exit this page.

Errata?  SQL Server technology is changing and we strive to update our SQL Server support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:and include the URL for the page.

Burleson Consulting
SQL Server database support


Copyright © 1996 -  2013 by Vaaltech Web Services. All rights reserved.

Hit Counter