본문 바로가기

ASP_PHP_JSP 사용 비교

jsp sha256적용

728x90
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
 
    /**
     * SHA256 암호화 문자열로 변환
     * @param value
     * @return
     * @throws NoSuchAlgorithmException
     */
    public static String encryptSHA256(String value) throws NoSuchAlgorithmException{
        String encryptData = "";
         
        MessageDigest sha = MessageDigest.getInstance("SHA-256");
        sha.update(value.getBytes());
 
        byte[] digest = sha.digest();
        for (int i=0; i<digest.length; i++) {
            encryptData += Integer.toHexString(digest[i] & 0xFF).toUpperCase();
        }
         
        return encryptData;
    }
     
    /**
     * MD5 암호화 문자열로 변환
     * @param value
     * @return
     * @throws NoSuchAlgorithmException
     */
    public static String encryptMD5(String value) throws NoSuchAlgorithmException{
        String encryptData = "";
         
        MessageDigest sha = MessageDigest.getInstance("MD5");
        sha.update(value.getBytes());
 
        byte[] digest = sha.digest();
        for (int i=0; i<digest.length; i++) {
            encryptData += Integer.toHexString(digest[i] & 0xFF).toUpperCase();
        }
         
        return encryptData;
    }
 

 

 

출처 : https://blog.naver.com/samsonk

728x90