package util;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class SHA256 {
public static String getSHA256(String input) {
StringBuffer result = new StringBuffer();
try {
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] salt = "oshU>'tZf;SSea1.6+o8#?F0%e)7?}".getBytes();
digest.reset();
digest.update(salt);
byte[] chars = digest.digest( input.getBytes("utf-8") );
for(int i =0; i<chars.length; i++) {
String hex = Integer.toHexString(0xFF & chars[i]);
if( hex.length() == 1 ) {
result.append('0');
}
result.append(hex);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println(e.toString());
}
return result.toString();
}
}
'개발 > Java' 카테고리의 다른 글
Java StringBuffer란 (0) | 2019.12.16 |
---|---|
Java Boolean to Int (0) | 2019.12.05 |
이클립스 자동완성 키 변경 (0) | 2019.11.29 |
Java Combination, Permuation 순열과 조합 (0) | 2019.11.02 |
Java Input.txt에서 입력받기 (0) | 2019.11.02 |