Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package eu.ownii.quiz.statics;
- import java.io.UnsupportedEncodingException;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- public class MD5 {
- public static String hash(String string) throws Exception {
- String digest = null;
- try {
- MessageDigest md = MessageDigest.getInstance("MD5");
- byte[] hash = md.digest(string.getBytes("UTF-8"));
- //converting byte array to Hexadecimal String
- StringBuilder sb = new StringBuilder(2*hash.length);
- for(byte b : hash){
- sb.append(String.format("%02x", b&0xff));
- }
- digest = sb.toString();
- } catch (UnsupportedEncodingException ex) {
- } catch (NoSuchAlgorithmException ex) {
- }
- return digest;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement