Question : HMAC-MD5 (RFC 2104) VB

I'm looking for some VB.NET HMAC MD5 code (as defined in RFC 2104 http://tools.ietf.org/html/rfc2104).

This is for some integration with LinkShare when an XML file needs to be encrypted with a key.  The example in their documentation states:

1. Here is the raw transaction string:

<message xmlns="http://www.linkshare.com/namespaces/realtime-transactions-1.0">
<sku_order>
<orderid>12345</orderid>
<siteid>lKW2Xiq9xN0-4.c_9w1X8ZpO94TUl4hg3D</siteid>
<time_entered>2007-09-18T02:20:00Z</time_entered>
<currency>USD</currency>
<trans_date>2007-09-18T20:02:00Z</trans_date>
<item>
<sku>productA_sku</sku>
<quantity>3</quantity>
<amount>30000</amount>
<product_name>product A</product_name>
</item>
<item>
<sku>productB_sku</sku>
<quantity>1</quantity>
<amount>1000</amount>
<product_name>product B</product_name>
</item>
</sku_order>
</message>

2. Pass the raw transaction string and your key (provided by LinkShare) through an HMAC-MD5 function to obtain the MAC value:

v‚s> [õTżOEÑ ƒ

In this example, the key used is xxxxxyyyy.

=============================================================

I can replicate this with the following PHP code:

function hmac ($key, $data)
{

$b = 64; // byte length for md5
if (strlen($key) > $b) {
$key = pack("H*",md5($key));
}
$key = str_pad($key, $b, chr(0x00));
$ipad = str_pad('', $b, chr(0x36));
$opad = str_pad('', $b, chr(0x5c));
$k_ipad = $key ^ $ipad ;
$k_opad = $key ^ $opad;

return md5($k_opad . pack("H*",md5($k_ipad . $data)));
}

$md5_raw = hash_hmac("md5", "KeyHere", "DataHere", true);
echo $md5_raw;

=============================================================

All the VB examples I can find output a hex value, the PHP example seems to output raw binary.  How can this be done in VB?

Any help, VB .Net or VB6 will do!

Answer : HMAC-MD5 (RFC 2104) VB

I suspect you mean that you want to convert your hex-value into a byte or byte-array?

http://www.devx.com/vb2themax/Tip/18808 shows how to convert hexadecimal to integers. By passing not more than two chars at any time, you can create a byte-array easily.

Random Solutions  
 
programming4us programming4us