java - Can someone explain the conversion from byte array to hex string? -
I recently started looking for MD5 hashing (in Java) and I have got to help complete the algorithms and methods, I think how it actually works.
For one, I found out of the following:
Convert Private Static String ToHex (Byte [] data) {StringBuffer buf = new stringbuffer (); {Int halfbyte = (data [i]>>> 4) & amp; nbsp; (for int i = 0; i & lt; data lamps; i ++) & amp; 0x0F; Int two_halfs = 0; Do it {if (0> = halfbyte) & ampby; (halfbyte & lt; = 9)) buf.append ((four) ('0' + halfbyte)); Else buf.append ((four) ('a' + (halfbyte - 10)); Half-bite = data [i] & amp; 0x0F; } While (two_half ++ & lt; 1); } Return buf.toString (); }
I do not need to use bit-shifting in Java, so I'm a little disturbing on that enough to explain to someone (in simple words) the above code conversion How does ">>>"?
I also found other solutions on the stack overflow, like, and, which instead uses the bigteger:
try {string s = "test STRING"; MessageDigest md5 = MessageDigest.getInstance ("MD5"); Md5.update (s.getBytes (), 0, s.length ()); String signature = new bigigner (1, MD5 digest) Tosting (16); System.out.println ("Signature:" + Signature); } Catch (Last Knowledge Algorithm Exposure E) {e.printStackTrace (); }
Why does this work too, and how is it more efficient?
Thank you for your time. {StringBuffer buf = new StringBuffer ())