Solved

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

Posted on 2007-11-22
3
978 Views
Last Modified: 2010-04-21
Here is the VB.net 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 & _
          aws_GetISOTimestamp(TimeStamp)
   
       objUTF8Encoder = New UTF8Encoding()
       strSig_UTF8 = objUTF8Encoder.GetBytes(strSig_Raw)
   
       objHMACSHA1 = New HMACSHA1( _
          objUTF8Encoder.GetBytes(m_strSecretAccessKey))
       strSignature = Convert.ToBase64String _
          (objHMACSHA1.ComputeHash( _
          objUTF8Encoder.GetBytes( _
          strSig_Raw.ToCharArray())))
   
       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?

Kevin
0
Comment
Question by:zorvek (Kevin Jones)
3 Comments
 
LVL 49

Accepted Solution

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


HCRYPTPROV  m_hProv;
HCRYPTHASH  m_hHash;
HCRYPTKEY   m_hKey;
 
char* pszKey="someSecretKeyText";
m_fOK= CryptAcquireContext(&m_hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT );
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

0
 
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
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

By default, Carbonite Server Backup manages your encryption key for you using Advanced Encryption Standard (AES) 128-bit encryption. If you choose to manage your private encryption key, your backups will be encrypted using AES 256-bit encryption.
Encryption for Business Encryption (https://en.wikipedia.org/wiki/Encryption) ensures the safety of our data when sending emails. In most cases, to read an encrypted email you must enter a secret key that will enable you to decrypt the email. T…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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