blob: 7c77ddf510c33e3de52ad25d5c74c3fb38ca3351 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
package org.apache.tuscany.das.ldap.encryption.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.apache.tuscany.das.ldap.encryption.constants.EncryptionConstants;
public class ChecksumUtils
implements EncryptionConstants
{
public static String computeMD5Hash(String string)
throws NoSuchAlgorithmException
{
MessageDigest messageDigest = MessageDigest.getInstance(MD5);
byte[] digest =
messageDigest.digest(string.getBytes());
StringBuffer hexString = new StringBuffer();
for (int i=0;i<digest.length;i++) {
hexString.append (
Integer.toHexString(0xFF & digest[i]));
}
char[] hexStringCharacters = hexString.toString().toCharArray();
String checksum = "";
for( char i : hexStringCharacters)
{
int ascii = (int) i;
checksum = checksum + Integer.toString(ascii);
}
return checksum;
}
}
|