This content has been marked as final.
Show 3 replies
-
1. Re: problems with MD5 encoding
rohithadg Jan 5, 2009 7:46 AM (in response to felixk123)This may be help you.
public String getMD5(String str) throws NoSuchAlgorithmException { MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); digest.update(str.getBytes()); byte[] hash = digest.digest(); return hexStringFromBytes(hash); } public String hexStringFromBytes(byte[] b){ char[] hexChars ={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; String hex = ""; int msb; int lsb = 0; int j; // MSB maps to idx 0 for (j = 0; j < b.length; j++){ msb = ((int)b[j] & 0x000000FF) / 16; lsb = ((int)b[j] & 0x000000FF) % 16; hex = hex + hexChars[msb] + hexChars[lsb]; } return(hex); }
-
2. Re: problems with MD5 encoding
felixk123 Jan 5, 2009 9:22 AM (in response to felixk123)I need the MD5 encoding with base64. How do I get it with your method so that the result for the string "hendrix" is "schPjWcrXWqEp6SG6BtGWg==".
The result with your method with bas64 for "hendrix" was "QjFDODRGOEQ2NzJCNUQ2QTg0QTdBNDg2RTgxQjQ2NUE=" and the result with the jdk was "schPP2crXWqEp6SG6BtGWg==". -
3. Re: problems with MD5 encoding
felixk123 Jan 9, 2009 5:59 AM (in response to felixk123)problem solved...it was my mistake.
withencoded = new BASE64Encoder().encode(md5);
does it work.