Dear Folks, I am no good in data structure and algorithm specially due to very rich collection api of java. But now-a-days I am working on a few projects that requires language independent solutions to DSA problems. I was thinking to attend an online training course on that...short (may be in C++) but effective so that after the course I can carry on myself. If you know a few links, please let me know (I tried google and got so many links that made me lost in forest). One of my recently developer java xmlrpc client works fine that interacts with an xmlrpc server developed in python. Now I need to do md5 checksum of my sent data to the server that also checks whether data was modified during transport. But the data I get after digest is not matching with the data produced as a result of MD5 digesting by my python server. As I know, MD5 is a non-reversable(or almost?!) two-step way to generate a checksum value that should generate the same checksum every time the same input is given to digest. Then as my one is not matching, I am a little worried where am I making the mistake? The current digest is accepted by the python server but that doesn't that help me. I tested generating though python's code the "Hello World" string and got this following digest - b10a8db164e0754105b7a99be72e3fe5
But when I print it in Java, it gets me. I tried it in PHP to see if "Hello World" gives the same value. Yes, the following code generates the same.
The following methods are used in one of my utility class.
The value I get are - ������*$���v or when padded the bytes ffffffb3ffffff8bffffffe257f99ffffff92ffffff88fffffff62a24ffffffe1ffffff8affffffc476
The problem is XMLRPC sends good XML content via HTTP and so it can't send this sort of bytes-looking data, this contradicts with the XML encoding while trying to wrap up over the wire. Then I tried preparing padHexString() (with hope to make single byte 0-9 as 00-09) and returnHexString() (with hope I'll get something out of Integer.toHexString) seperately. combinedly etc in various orders, but could not generate the b10a8db164e0754105b7a99be72e3fe5 digest in java. Probabvly I need to know more on MD5 Can you help me through some comments? My idea is just to generate b10a8db164e0754105b7a99be72e3fe5 from "Hello World" using MD5 digest in Java. [fixed the width of the code example - Ilja] [ May 11, 2004: Message edited by: Ilja Preuss ]
Ashik Uzzaman Senior Member of Technical Staff, Salesforce.com, San Francisco, CA, USA.
One thing to be very careful about here is the use of Strings. MD5 takes a sequence of bytes as input and returns a sequence of bytes as output. There may be descrepencies in how the Java and Python versions convert strings to byte arrays. Also, note this line: sReturnStr = new String( md5.digest() ); That's asking for trouble. Your binary is being converted into a string using whatever the local encoding may be. Converting random binary bits to Strings will usually have unexpected results (if it works at all). If you convert your code to think in terms of byte arrays instead of strings and to ensure that the conversion between strings and byte arrays behaves the same in both the python and java versions, that may fix your problem.
You wrote: <CITE> Some tasks which are childishly simple in other languages, are made unnecessarily(?!) complex in Java. If you don't agree, see the 3 line python code and 1 line PHP code that I posted at the very top. </CITE> Well, computing an MD5 digest is intentionally and inherently difficult. Otherwise it could be a usable digest. You can have an easy coding in Java too, if relying upon a given infrastructure: private final static String DIGEST_ALGO = "MD5"; String PasswordDigest = org.apache.catalina.realm.RealmBase.Digest(user_pass,DIGEST_ALGO);
This thread seems to be more appropriate for the Security forum - moving ...
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus