By registering with us, you'll be able to discuss, share and private message with other members of our community.
SignUp Now!Dim StringToSign As String
StringToSign = signable_string
Dim bytStringToSign() As Byte
bytStringToSign = HS256.ToUTF8(StringToSign)
StringToSign = ""
Dim bytSecretKey() As Byte
bytSecretKey = HS256.ToUTF8(ESL_Settings.PrivateKey)
'Initialize the HMAC with our Key:
HS256.InitHmac bytSecretKey
Erase bytSecretKey
'Create the Signature hash:
Dim bytSignature() As Byte
bytSignature = HS256.HmacSha256(bytStringToSign)
Erase bytStringToSign
'Convert the Signature to Base64:
Dim Base64Signature As String
Base64Signature = HS256.Encode(bytSignature, edfBase64, efNoFolding)
Erase bytSignature
Debug.Print Base64Signature
Base64Signature = HS256.Encode(bytSignature, edfBase64, efNoFolding)
Base64Signature = HS256.Encode(bytSignature, edfBase64, efLf)
Public Shared Function HashString(ByVal StringToHash As String, ByVal PrivateKey As String) As String
Dim myEncoder As New System.Text.UTF8Encoding
Dim Key() As Byte = myEncoder.GetBytes(PrivateKey)
Dim Text() As Byte = myEncoder.GetBytes(StringToHash)
Dim myHMACSHA1 As New System.Security.Cryptography.HMACSHA256(Key)
Dim HashCode As Byte() = myHMACSHA1.ComputeHash(Text)
Return Convert.ToBase64String(HashCode)
End Function
Well, I guess it did not work.
For some reason it worked once (Or appeared to).
Input string: (Each line ends in a Chr$(10))
87c9320aa8834dffbf5887046713187a
1411317388
POST
/e/csl/products/update
Output from Class:
au9MEWefulSThFOdIIzt796TU1uhbeSZWu1NAe6+aac=
Output from Server:
Ig/pGE6kkRC8I370J2OTek3cGVgK5aEoSFGs1jD1FXk=
I tried this VB.Net2008 code and it works, but the project is in VB6
...
Any ideas would be great
If blnIsWinXP And (Format = edfHexRaw) Then
Private Sub Class_Initialize()
If CryptAcquireContext(hBaseProvider, _
0&, _
StrPtr(MS_DEFAULT_PROVIDER), _
PROV_RSA_FULL, _
CRYPT_VERIFYCONTEXT Or CRYPT_MACHINE_KEYSET) = 0 Then
Err.Raise vbObjectError Or &HC366&, _
"HS256.Class_Initialize", _
"Failed to obtain CryptoAPI Base context, system error " _
& CStr(Err.LastDllError)
ElseIf CryptAcquireContext(hAdvProvider, _
0&, _
StrPtr(MS_ENH_RSA_AES_PROV), _
PROV_RSA_AES, _
CRYPT_VERIFYCONTEXT Or CRYPT_MACHINE_KEYSET) <> 0 Then Exit Sub
End If
If CryptAcquireContext(hAdvProvider, _
0&, _
StrPtr(MS_ENH_RSA_AES_PROV_XP), _
PROV_RSA_AES, _
CRYPT_VERIFYCONTEXT Or CRYPT_MACHINE_KEYSET) = 0 Then
Err.Raise vbObjectError Or &HC368&, _
"HS256.Class_Initialize", _
"Failed to obtain CryptoAPI RSA AES context, system error " _
& CStr(Err.LastDllError)
End If
End Sub
I have set VB6.EXE to XP SP3 compatibility mode because I have flicker problem with dragging controls in designer, therefore it's not without a reason. I'm using Windows 8 and still have these problems, so it not like you said.
It still gives me false data under Windows 8.
Edit:
I found the problem - it is in Encode/Decode function on this line of code:That is skipped because blnIsWinXP is set to False, but I've removed that check there and it works now as it should.Code:If blnIsWinXP And (Format = edfHexRaw) Then
Also, in its initialization event I've removed system version check and changed it to much easier trial and error approach:
Hi, What was your solution?My solution works now on both Windows XP and 8.... I resorted to the most trivial way.