Unable to find source I ported the following HMAC-MD5 algorithm. It could
probably be optimized but..
public byte[] HMACMD5(string strKey, string strText)
{
MD5CryptoServic eProvider cspMD5 = new MD5CryptoServic eProvider();
byte[] bText = Encoding.ASCII. GetBytes(strTex t);
byte[] bKey = Encoding.ASCII. GetBytes(strKey );
byte[] ipad = new byte[64];
byte[] opad = new byte[64];
byte[] idata = new byte[64 + bText.Length];
byte[] odata = new byte[64 + 16];
if (bKey.Length > 64)
bKey = cspMD5.ComputeH ash(bKey);
byte[] bPass1 = cspMD5.ComputeH ash(bKey);
for (int i = 0 ; i < 64 ; i++)
{
idata[i] = ipad[i] = 0x36;
odata[i] = opad[i] = 0x5C;
}
for (int i = 0 ; i < bKey.Length ; i++)
{
ipad[i] ^= bKey[i];
opad[i] ^= bKey[i];
idata[i] = (ipad[i] &= 0xFF);
odata[i] = (opad[i] &= 0xFF);
}
for (int i = 0 ; i < bText.Length ; i++)
idata[64 + i] = (bText[i] &= 0xFF);
byte[] innerhashout = cspMD5.ComputeH ash(idata);
for (int i = 0 ; i < 16 ; i++)
odata[64 + i] = innerhashout[i];
return cspMD5.ComputeH ash(odata);
}
probably be optimized but..
public byte[] HMACMD5(string strKey, string strText)
{
MD5CryptoServic eProvider cspMD5 = new MD5CryptoServic eProvider();
byte[] bText = Encoding.ASCII. GetBytes(strTex t);
byte[] bKey = Encoding.ASCII. GetBytes(strKey );
byte[] ipad = new byte[64];
byte[] opad = new byte[64];
byte[] idata = new byte[64 + bText.Length];
byte[] odata = new byte[64 + 16];
if (bKey.Length > 64)
bKey = cspMD5.ComputeH ash(bKey);
byte[] bPass1 = cspMD5.ComputeH ash(bKey);
for (int i = 0 ; i < 64 ; i++)
{
idata[i] = ipad[i] = 0x36;
odata[i] = opad[i] = 0x5C;
}
for (int i = 0 ; i < bKey.Length ; i++)
{
ipad[i] ^= bKey[i];
opad[i] ^= bKey[i];
idata[i] = (ipad[i] &= 0xFF);
odata[i] = (opad[i] &= 0xFF);
}
for (int i = 0 ; i < bText.Length ; i++)
idata[64 + i] = (bText[i] &= 0xFF);
byte[] innerhashout = cspMD5.ComputeH ash(idata);
for (int i = 0 ; i < 16 ; i++)
odata[64 + i] = innerhashout[i];
return cspMD5.ComputeH ash(odata);
}