[jboss-user] [Beginners Corner] - Re: problems with MD5 encoding
rohithadg
do-not-reply at jboss.com
Mon Jan 5 07:46:34 EST 2009
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);
| }
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4199530#4199530
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4199530
More information about the jboss-user
mailing list