Mercurial Hosting > nabble
comparison src/fschmidt/util/java/MD5Util.java @ 68:00520880ad02
add fschmidt source
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 05 Oct 2025 17:24:15 -0600 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:9d0fefce6985 | 68:00520880ad02 |
---|---|
1 package fschmidt.util.java; | |
2 | |
3 import java.io.UnsupportedEncodingException; | |
4 import java.security.MessageDigest; | |
5 import java.security.NoSuchAlgorithmException; | |
6 | |
7 public class MD5Util { | |
8 public static String hex(byte[] array) { | |
9 StringBuffer sb = new StringBuffer(); | |
10 for (byte anArray : array) { | |
11 sb.append(Integer.toHexString((anArray | |
12 & 0xFF) | 0x100).substring(1, 3)); | |
13 } | |
14 return sb.toString(); | |
15 } | |
16 | |
17 public static String md5Hex(String message) { | |
18 try { | |
19 MessageDigest md = | |
20 MessageDigest.getInstance("MD5"); | |
21 return hex(md.digest(message.getBytes("CP1252"))); | |
22 } catch (NoSuchAlgorithmException e) { | |
23 } catch (UnsupportedEncodingException e) { | |
24 } | |
25 return null; | |
26 } | |
27 } |