UNID Encoder


package com.ZetaOne.util;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class UNIDEncoder {

	public UNIDEncoder() {
	}

	public static String hex(byte[] array) {
		StringBuffer buff = new StringBuffer();
		for (int b = 0; b < array.length; b++) {
			buff.append(Integer.toHexString((array[b] & 0xFF) | 0x100).substring(1, 3));
		}
		return buff.toString().toUpperCase();
	}

	public static String encode(String message) {
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			return hex(md.digest(message.getBytes("CP1252")));
		} catch (NoSuchAlgorithmException e) {
		} catch (UnsupportedEncodingException e) {
		}
		return null;
	}
}
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...