[java] MD5 Hash 구현.

ITWeb/개발일반 2013. 8. 27. 18:34

MessageDigest 랑 Spring 의 DigestUtils 로 구현된 예제 입니다.


public static String getMd5(String input) throws Exception {

//        MessageDigest md = MessageDigest.getInstance("MD5");

//        md.update(Constants.HASH_KEY_PHRASE.getBytes());

// 

//        byte[] bytesInput = input.getBytes("UTF-8");

//        byte byteData[] = md.digest(bytesInput);        

//        StringBuffer strBuffer = new StringBuffer();

//        

//        for (int i = 0; i < byteData.length; i++) {

//                strBuffer.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));

//        }

//        

//        return strBuffer.toString();


           byte[] bytesInput = input.getBytes("UTF-8");

           String cipher = DigestUtils.md5DigestAsHex(bytesInput);


           return cipher;

}


: