diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/fschmidt/util/java/MD5Util.java	Sun Oct 05 17:24:15 2025 -0600
@@ -0,0 +1,27 @@
+package fschmidt.util.java;
+
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+public class MD5Util {
+	public static String hex(byte[] array) {
+		StringBuffer sb = new StringBuffer();
+		for (byte anArray : array) {
+			sb.append(Integer.toHexString((anArray
+					& 0xFF) | 0x100).substring(1, 3));
+		}
+		return sb.toString();
+	}
+
+	public static String md5Hex(String message) {
+		try {
+			MessageDigest md =
+					MessageDigest.getInstance("MD5");
+			return hex(md.digest(message.getBytes("CP1252")));
+		} catch (NoSuchAlgorithmException e) {
+		} catch (UnsupportedEncodingException e) {
+		}
+		return null;
+	}
+}
\ No newline at end of file