473,385 Members | 1,587 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1095

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

Similar topics

2
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
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
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
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
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
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
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
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
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
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.