最終更新:2012.12.14

MD5ハッシュ化クラス

/* Class Digest This class creates MD5 digest with hex string from input string. 2012.12.07 */ import java.security.*; import java.lang.*; public class Digest{ public String encrypt(String raw){ byte[] in = raw.getBytes(); // convert raw text to byte String temp = new String(); // use for temporaly StringBuffer sb = new StringBuffer(); // create hex string byte[] out = null; // store MD5 encrypted data from input text try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(raw.getBytes()); out = md.digest(); for (int i = 0;i < out.length;i = i + 1){ if (out[i] < 0){ temp = Integer.toHexString(out[i] + 256); } else { temp = Integer.toHexString(out[i]); } sb.append(temp); } } catch (NoSuchAlgorithmException e) { System.out.println("no such Algorism"); } return sb.toString(); } }

戻る