-
1 Attachment(s)
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
Well, I've got a report for HS512 class on Windows 8.1 64-bit that this error has shown:
Attachment 134197
And this is the code which is calling the class:
Code:
With hs5
.InitHmac .ToUTF8(server_seed)
roll_hash = .Encode(.HmacSha512(.ToUTF8("1-" & i)))
End With
What it could be, how to solve it? On my Windows 7 32-bit it's working perfectly though.
-
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
The one who sent me the screenshot from above corrected himself that he's using Windows 8.1 (not 8), so I've corrected that in the above post and searched for that error, and I've found this: http://stackoverflow.com/questions/1...nswer-19965034
Since its' cause is probably that system bug it can't be fixed, eh?
-
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
Odd.
I just tried the demo program on a Windows 10 x64 system and it works fine there.
https://rcpmag.com/articles/2016/01/...-deadline.aspx
Quote:
As of Jan. 12, 2016, Windows 8 is now considered to be "unsupported" by Microsoft, meaning the company will no longer issues hotfixes or security updates for the operating system. Exceptions to this policy might be organizations that have purchased Microsoft's "custom support," but that option is thought to be an expensive one, with contracts lasting just a year.
So Windows 8 is dead anyway, but Win8.1 Update 1 (or is it Update 2?) should still be supported for a little while. If somebody reports the bug there is a chance it might get fixed. However they really, really, really want people to move off 8.x OSs entirely so maybe it won't.
-
1 Attachment(s)
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
Quote:
Originally Posted by
dilettante
Odd.
I just tried the demo program on a Windows 10 x64 system and it works fine there.
I can't get the HS256 class working with Windows 10 x64 Excel. All the "Declare Kernal32" functions are red and I get the following error:
Attachment 141555
-
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
Quote:
Originally Posted by
dilettante
Odd.
I just tried the demo program on a Windows 10 x64 system and it works fine there.
The HS256 class is not working for me in Windows 10 Excel x64. All the "Declare Kernal32" lines are red and I get an error about 64bit compatibility if I try to create one.
-
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
You will have to go through it and make the necessary changes. Part of the problem with 64-bit Office and later versions of Office in general is that VBA6.5 and VBA7 lose some VB6 compatibility.
Add the PtrSafe decorator to Declare statements, and change the type of pointer and handle arguments from Long to LongPtr.
See PtrSafe <keyword>
I don't have 64-bit Excel to test with.
-
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
Hi, dilettante
First of all thank you for the project sample, i have problem using this class to my case.
i have this this data:
Data: hypermart1468914526
Key: a4f6bf89b2a85781b7c1cab997b7ee0c89be03f7ac6ef29b63a45d07253cc401
i have tested in http://codebeautify.org/hmac-generator with HMAC-SHA256 and the result was correct.
How i implement this with your class.
Thank you
-
2 Attachment(s)
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
That web page sort of sucks.
The "key" value must be entered as printable/typeable text, you can't use a string of hex digits. If you do that it just takes it as text and you get an incorrect HMAC value there.
Here's an example with optional "sucks" mode:
-
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
Quote:
Originally Posted by
dilettante
That web page sort of sucks.
The "key" value must be entered as printable/typeable text, you can't use a string of hex digits. If you do that it just takes it as text and you get an incorrect HMAC value there.
Here's an example with optional "sucks" mode:
Thank you for you sample dilettante, it works as expected.
here is my code before
Code:
Private Sub Command1_Click()
Dim xKey As String
Dim xData As String
Dim bSig() As Byte
Dim StringToSign() As Byte
Dim secretKey() As Byte
xKey = "a4f6bf89b2a85781b7c1cab997b7ee0c89be03f7ac6ef29b63a45d07253cc401"
xData = "hypermart1468914526"
With hs256
StringToSign = .ToUTF8(xData)
secretKey = .ToUTF8(xKey)
.InitHmac secretKey
Erase secretKey
bSig = .HmacSha256(StringToSign)
Erase StringToSign
MsgBox .Encode(bSig, edfBase64, efNoFolding)
Erase bSig
End With
End Sub
i realize that the msgbox line was the cause why the result always incorrect, after removing edfBase64 and efNoFolding the result was correct
-
1 Attachment(s)
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
Another version that might work better in some scenarios. It only uses the default Base Provider.
However note that this might only work on newer versions of Windows. See Microsoft Base Cryptographic Provider:
Quote:
To maintain backward compatibility with earlier versions the new version of the provider retains the version 1.0 designation of the name in Wincrypt.h. However, version 2.0 of this provider is currently shipping. To determine the actual version of the provider in use, call CryptGetProvParam with the dwParam argument set to PP_VERSION. If 0x0200 is returned in pbData, then you have version 2.0.
So while the operations my class performs are working under Windows 10 they may rely on things that are only in version 2.0 of this Provider.
Tested and works on Windows 10 1709 and on Windows Home Server 2011 SP 1 (basically the Windows 7 codebase).
-
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
All 7 cases in HS512 Demo 1-2 Base.zip seem to work fine on Windows Server 2013 here.
cheers,
</wqw>
-
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
Please help a self-taught VBA user that can’t quite close the knowledge gap and use the Excel class that dilettante provided. Does the HS256 Excel demo from post #59 contain the code necessary for the following problem that I have?
I am trying sign a request for an API. The secret key below is an example. The CB-ACCESS-SIGN header is generated by creating a sha256 HMAC using the base64-decoded secret key on the prehash string and base64-encode the output. “1522000342.391” is the timestamp in UNIX Epoch time.
Prehash string:
1522000342.391POST/orders{"price":“1.0”,“size”:“1.0”,“side”:“buy”,“product_id”:“BTC-USD”}
Secret key:
D1/0wNj3wsKg8XcTs4KCfZUVzsHXIOW7w38Moj+YximHA5VQS7zAG47bgNSNGIGtFtYQ0vei2JiSPvX3JkBsA==
-
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
How to validate the Signature ? I am using below php code:
PHP Code:
function dec_enc($action, $string) {
$output = false;
$encrypt_method = "AES-256-CBC";
$secret_key = 'This is my secret key';
$secret_iv = 'This is my secret iv';
// hash
$key = hash('sha256', $secret_key);
// iv - encrypt method AES-256-CBC expects 16 bytes - else you will get a warning
$iv = substr(hash('sha256', $secret_iv), 0, 16);
if( $action == 'encrypt' ) {
$output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
$output = base64_encode($output);
}
else if( $action == 'decrypt' ){
$output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
}
return $output;
}
-
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
what about CryptBinaryToStringA sha512?
-
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
Quote:
Originally Posted by
dilettante
You will have to go through it and make the necessary changes. Part of the problem with 64-bit Office and later versions of Office in general is that VBA6.5 and VBA7 lose some VB6 compatibility.
Add the
PtrSafe decorator to Declare statements, and change the type of pointer and handle arguments from
Long to
LongPtr.
See
PtrSafe <keyword>
I don't have 64-bit Excel to test with.
Hi.
I've added PtrSafe and changed Long to LongPtr (where necessary) in declarations , but the "HS256 Demo 3-1" does not work. It throws "Failed to import key, system error 87". Would it be possible to amend the HS256 Demo 3-1 to be operative in 64-bit Excel ?
-
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
Error 87 is "The parameter is incorrect."
I suspect you may have changed some Long arguments to LongPtr where they shouldn't be changed. DWORD is an example of a data type that is still 32 bits on an x64 Windows installation.
-
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
Quote:
Originally Posted by
dilettante
Error 87 is "The parameter is incorrect."
I suspect you may have changed some Long arguments to LongPtr where they shouldn't be changed. DWORD is an example of a data type that is still 32 bits on an x64 Windows installation.
Dear Dilettante.
I've changed Long to LongPtr where the VBE demands it for successful compilation.
The amended project is at the link: https://drive.google.com/file/d/1va8...ew?usp=sharing
Could you kindly look into it to detect an incorrect thing ?
-
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
Quote:
Originally Posted by
dilettante
Error 87 is "The parameter is incorrect."
I suspect you may have changed some Long arguments to LongPtr where they shouldn't be changed. DWORD is an example of a data type that is still 32 bits on an x64 Windows installation.
Dear Dilettante
I've changed Long to LongPtr where the VBE demands it for successful compilation. May I send you the amended HmacSha256Demo and ask you to look into it and correct as necessary ?
-
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
You can copy the PtrSafe API declares from WinXP compatible HMAC codebank submission which is x64 compatible.
In x64 version of the OS the handles are 64-bit too i.e. must use LongPtr parameters *and* variables for hKey, hHash, hProv, etc.
cheers,
</wqw>
-
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
Quote:
Originally Posted by
wqweto
You can copy the PtrSafe API declares from
WinXP compatible HMAC codebank submission which is x64 compatible.
In x64 version of the OS the handles are 64-bit too i.e. must use LongPtr parameters *and* variables for hKey, hHash, hProv, etc.
cheers,
</wqw>
Dear wqweto .
Thank you indeed.
The sample (given in your topic) works well in x64 Excel.
-
Re: [VB6] HMAC-SHA-256, HMAC-SHA-1 Using Crypto API
Hi dilettante, can help me? need to sign a string with sha1 and base64 please.