Programming/java

[java] MD5 암호화

성일만 2014. 6. 18. 15:38

MD5 암호화



import java.security.MessageDigest;

import java.security.NoSuchAlgorithmException;


public class Encrypt {

    public static String encrypt(String str) throws NoSuchAlgorithmException {

        String encData = "";
        
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] bytes = str.getBytes();
            md.update(bytes);
            byte[] digest = md.digest();

            for(int i=0; i<digest.length; i++ ) {
                encData += Integer.toHexString(digest[i]&0xff);
            }

        } catch (NoSuchAlgorithmException e) {
            // TODO: handle exception
            e.printStackTrace();
            throw e;
        }

        return encData; 
    }
}






출처 : http://kamsi76.egloos.com/viewer/361968

'Programming > java' 카테고리의 다른 글

[java] JavaSE 환경설정  (0) 2014.09.17
[java] serialVersionUID를 선언하는 이유  (0) 2014.09.02
[java] static 키워드  (0) 2014.09.02
[Java] 입력받은 정수를 역순으로 출력  (0) 2014.02.26
[Java] Bubble Sort Algorithm  (0) 2014.02.26