SHA1 Hash on Hex String

I'm trying to hash a number, represented by hex string with Java security library. Meaning, If I have the String "AABBCCDD" I want to hash it not as this is an ascii input, which is 0x65, 0x65, 0x66, 0x66, 0x67, 0x67, 0x68, 0x68, but as four bytes - 0xAA, 0xBB, 0xCC, 0xDD. I managed to do it with low values such as "112233445566" (since bytes are signed in Java) but failed with high values.

Does someone know how to implement such thing?

Thanks, Binyamin

Answers


First convert your hex into byte[] using for example this: Convert a string representation of a hex dump to a byte array using Java?

After it use

byte[] data = hexStringToByteArray(hexData);
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(data, 0, data.length);
byte[] sha1hash = md.digest();

Need Your Help

IIS7 set error page to be displayed if timeout expire error

c# asp.net iis iis-7

I am using ASP.NET 2.0 with C#. I have a web-site (NOT the web-application) hosted on IIS7.

Trying to decode 128bit or 256 bit string?

decode encode encryption

the password string is some kind of like that

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.