473,503 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HMAC-MD5 (Giving back)

Unable to find source I ported the following HMAC-MD5 algorithm. It could
probably be optimized but..

public byte[] HMACMD5(string strKey, string strText)
{
MD5CryptoServiceProvider cspMD5 = new MD5CryptoServiceProvider();

byte[] bText = Encoding.ASCII.GetBytes(strText);
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.ComputeHash(bKey);

byte[] bPass1 = cspMD5.ComputeHash(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.ComputeHash(idata);

for (int i = 0 ; i < 16 ; i++)
odata[64 + i] = innerhashout[i];

return cspMD5.ComputeHash(odata);
}
Nov 22 '05 #1
0 1097

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1651
by: Ajay | last post by:
hi! i am calculating a digest of some data (using hmac) and printing it to a cookie. the problem is the hash may contain special characters. when these are printed they get converted to...
92
6331
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
5
2454
by: Steve Holden | last post by:
This is even stranger: it makes it if I import the module a second time: import dbimp as dbimp import sys if __name__ == "__main__": dbimp.install() #k = sys.modules.keys() #k.sort() #for...
12
2090
by: rbt | last post by:
I have written a python socketServer program and I have a few questions that I hope the group can answer... here is a simple version of the server: class...
11
1531
by: Fernando Barsoba | last post by:
Hi all, I very much need your help here guys.. I'm working on a IPSec implementation, and when almost finished, I found a considerable problem. I'm sending a particular array + a key to a...
2
2510
by: Fernando Barsoba | last post by:
Dear all, I have been posting about a problem trying to encrypt certain data using HMAC-SHA1 functions. I posted that my problem was solved, but unfortunately, I was being overly optimistic. I...
2
2850
by: ed | last post by:
Hello, I've been crawling the net tonight looking for a reasonably portable sha1/hmac implementation. I don't need a huge library of different methods, don't suppose anyone has such a piece of...
5
4137
by: KW | last post by:
I'm trying to convert some PHP code using OpenSSL to Python and I'm stuck on openssl_sign() which uses an RSA private key to compute a signature. Example PHP code: $privkeyid =...
4
13251
by: Bhavesh.Feb | last post by:
Hi, I'm trying to use SHA1 and HMAC to create signature for my web service request. I dont know much about HMAC or SHA1 but this is what i need to create signature. What i'm trying to do is: ...
1
4930
by: mirandacascade | last post by:
I am attempting to implement a process, and I'm pretty sure that a major roadblock is that I do not understand the nomenclature. The specs indicate that the goal is to calculate a message digest...
0
7198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4998
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
373
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.