I am getting byte array from digest method. Then I would convert byte array into string using new String(byte) method. Afterwards, I would convert the same string into byte array using toBytes() method. While doing this, initial byte array and final byte array is different. I would assume that It should be same... Here is the sample code I am using..
"hits100" The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in again with a new name which meets the requirements. Thanks. Sean
I don't know what the problem is here. Try using methods which allow you to specify the encoding used - e.g. <pre> md.update(Password.getBytes("UTF-8")); ... String finalString = new String(b1, "UTF-8"); byte c1 = finalString.getBytes("UTF-8"); </pre> and see if that helps. It may also be useful to find out what the default encoding is on your machine - try <pre> System.out.println(new InputStreamReader(System.in).getEncoding()); </pre> to find out what that is. (I don't know why this info isn't more readily available via a System.getProperty() call, but this is the best way I know to find out.) Anyway, my thinking is that it's possible that there are some encodings which are not fully reversible - that is, the process is not one-to-one, and for some byte sequences there may be more than one way to encode (or decode). Echoing Ganesh's question, it would also be useful to see exactly what the difference was between the two byte arrays.
"I'm not back." - Bill Harding, Twister
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop