This is a follow-up question to a question I asked last month:
https://www.autohotkey.com/boards/viewtopic.php?t=60434
I need to make an AWS API call that requires lots of setup using hash functions.
Thanks to @vvhitevvizard, I was able to obtain a Hex2Bin function that helped me get further along the process.
The final part of the setup looks like this in Python code:
Code: Select all
signature = hmac.new(signing_key, (string_to_sign).encode('utf-8'), hashlib.sha256).hexdigest()
Code: Select all
bcrypt_sha256_hmac(string, hmac)
{
static BCRYPT_SHA256_ALGORITHM := "SHA256"
static BCRYPT_ALG_HANDLE_HMAC_FLAG := 0x00000008
static BCRYPT_HASH_LENGTH := "HashDigestLength"
if !(hBCRYPT := DllCall("LoadLibrary", "str", "bcrypt.dll", "ptr"))
throw Exception("Failed to load bcrypt.dll", -1)
if (NT_STATUS := DllCall("bcrypt\BCryptOpenAlgorithmProvider", "ptr*", hAlgo, "ptr", &BCRYPT_SHA256_ALGORITHM, "ptr", 0, "uint", BCRYPT_ALG_HANDLE_HMAC_FLAG) != 0)
throw Exception("BCryptOpenAlgorithmProvider: " NT_STATUS, -1)
if (NT_STATUS := DllCall("bcrypt\BCryptGetProperty", "ptr", hAlgo, "ptr", &BCRYPT_HASH_LENGTH, "uint*", cbHash, "uint", 4, "uint*", cbResult, "uint", 0) != 0)
throw Exception("BCryptGetProperty: " NT_STATUS, -1)
VarSetCapacity(pbInput, StrPut(string, "UTF-8"), 0) && cbInput := StrPut(string, &pbInput, "UTF-8") - 1
VarSetCapacity(pbSecret, StrPut(hmac, "UTF-8"), 0) && cbSecret := StrPut(hmac, &pbSecret, "UTF-8") - 1
VarSetCapacity(pbHash, cbHash, 0)
if (NT_STATUS := DllCall("bcrypt\BCryptHash", "ptr", hAlgo, "ptr", &pbSecret, "uint", cbSecret, "ptr", &pbInput, "uint", cbInput, "ptr", &pbHash, "uint", cbHash) != 0)
throw Exception("BCryptHash: " NT_STATUS, -1)
loop cbHash
hash .= Format("{:02x}", NumGet(pbHash, A_Index - 1, "uchar"))
DllCall("bcrypt\BCryptCloseAlgorithmProvider", "ptr", hAlgo, "uint", 0)
DllCall("FreeLibrary", "ptr", hBCRYPT)
return hash
}
Code: Select all
VarSetCapacity(pbSecret, StrPut(hmac, "UTF-8"), 0) && cbSecret := StrPut(hmac, &pbSecret, "UTF-8") - 1
Does anyone know how to work around this? A solution in AHK V1 would also be welcomed.
Thanks in advance for any help and consideration.