Добавлен метод хеширования в MD5
This commit is contained in:
parent
adc60671da
commit
7dc927f0ef
29
src/tse/lr4/Utils.java
Normal file
29
src/tse/lr4/Utils.java
Normal 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 "";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user