Need CryptCreateHash version of the HMACSHA1.ComputeHash .net function.

Posted on 2007-11-22
Last Modified: 2010-04-21
Here is the sample I am working with:

   Public Function aws_GetSignature _
       (ByVal Operation As String, ByVal TimeStamp As _
       DateTime) As String
       Dim strSig_Raw As String
       Dim strSig_UTF8 As Byte()
       Dim strSignature As String
       Dim objUTF8Encoder As UTF8Encoding
       Dim objHMACSHA1 As HMACSHA1
       strSig_Raw = "AmazonS3" & Operation & _
       objUTF8Encoder = New UTF8Encoding()
       strSig_UTF8 = objUTF8Encoder.GetBytes(strSig_Raw)
       objHMACSHA1 = New HMACSHA1( _
       strSignature = Convert.ToBase64String _
          (objHMACSHA1.ComputeHash( _
          objUTF8Encoder.GetBytes( _
       Return strSignature
   End Function

I have the ISOTimestamp, UTF-8 encoding, and base 64 functions working but need help with the HMACSHA1.ComputeHash function. How can I implement the HMACSHA1 function in VB6 using the CryptCreateHash Windows SDK function?

Question by:zorvek (Kevin Jones)
LVL 49

Accepted Solution

DanRollins earned 500 total points
ID: 20337761
Here's how I do it in C++ (I do add a bit of error checking...)





char* pszKey="someSecretKeyText";


m_fOK= CryptCreateHash(m_hProv, CALG_MD5, 0, 0, &m_hHash);

m_fOK= CryptHashData( m_hHash, (BYTE*)pszKey, strlen(pszKey), 0);

m_fOK= CryptDeriveKey( m_hProv, CALG_RC4, m_hHash, CRYPT_EXPORTABLE, &m_hKey);


... then later:

m_fOK= CryptEncrypt(m_hKey, 0, TRUE, 0, pData, dwDataLen, *dwDataLen);

Open in new window

LVL 81

Author Closing Comment

by:zorvek (Kevin Jones)
ID: 31410553
Dan, thanks for the response. It's a pretty tough problem with I never got working. But one of my coworkers found some code that appears to use the same API calls and successfully creates a hash. I just need to dissect it and figure out what they did that I did not do. Kevin

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Header of docx file 17 97
How to Add / Edit Windows Menu 4 51
Telco & Point to Point Internet VPN 3 77
Create Files based on Cell Values in a Range in Excel 12 17
SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
A simple description of email encryption using a secure portal service. This is one of the choices offered by The Email Laundry for email encryption. The other choices are pdf encryption which creates an encrypted pdf of your email and any attachmen…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now