UNID エンコーダー

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;
  }
}





静的メソッドを持つクラスで文字を取得してエンコードされたハッシュを返します。これをNSF 内のユニークなキーとして UNID として使用します。

document.setUniversalID(UNIDEncoder.encode("myUniqueString"));

Java
katoman
August 19, 2015 at 3:04 PM
Rating
0





No comments yetLogin first to comment...