Добавлен метод хеширования в MD5

This commit is contained in:
Victor 2013-11-25 22:21:41 +02:00
parent adc60671da
commit 7dc927f0ef

29
src/tse/lr4/Utils.java Normal file
View File

@ -0,0 +1,29 @@
package tse.lr4;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
*
* @author aNNiMON
*/
public class Utils {
public static String md5(String s) {
try {
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(s.getBytes());
byte[] messageDigest = digest.digest();
StringBuilder hexString = new StringBuilder();
for (int i = 0; i < messageDigest.length; i++) {
hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
}