Java Sha-256 메소드

Java Sha-256 메소드


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public static String sha256(String base) {
try{
MessageDigest digest = MessageDigest.getInstance("SHA-256");
byte[] hash = digest.digest(base.getBytes("UTF-8"));
StringBuffer hexString = new StringBuffer();
for (int i = 0; i<hash.length; i++) {
String hex = Integer.toHexString(0xff&hash[i]);
if(hex.length() == 1) hexString.append('0');
hexString.append(hex);
}
return hexString.toString();
} catch(Exception ex) {
throw new RuntimeException(ex);
}
}
Share