
MarkDowd (Community Member) asked a question.
The following documentation page provides examples of doing this in C#, Java and Python. Has anyone done it from PowerShell? We keep getting different signatures than when we do it from Java.
https://docs.veracode.com/r/c_enabling_hmac
Java (works in Postman)
----
function computeHashHex(message, key_hex) {
console.info('Full: ', CryptoJS.HmacSHA256(message, CryptoJS.enc.Hex.parse(key_hex)).toString(CryptoJS.enc.Hex));
return CryptoJS.HmacSHA256(message, CryptoJS.enc.Hex.parse(key_hex)).toString(CryptoJS.enc.Hex);
PowerShell (produces a different hash using the same parameters)
------------
function computeHashHex(
[string] $message,
[string] $key_hex
)
{
try {
$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha.key = [Text.Encoding]::UTF8.GetBytes($key_hex)
$hash = $hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($message))
$signature = [System.BitConverter]::ToString($hash).Replace("-","").ToLower()
} finally {
$hmacsha.Dispose()
}
return $signature
}
.png)
Hi @MarkDowd (Community Member) , a Veracode community member contributed this example a while ago:
https://github.com/rafaelzm2000/Veracode_HMAC_Auth
I haven't personally tested this (my daily driver is a MacBook Pro), but you might see if this works for you.
For future reference, there are other community contributed code samples here: https://github.com/veracode/Veracode-Community-Projects