import java.security.MessageDigest;


public class Sha256_Util {

public String encrypt(String planText){

try{

MessageDigest digest = MessageDigest.getInstance("SHA-256");

digest.update(planText.getBytes("UTF-8"));

byte[] byteData = digest.digest();

StringBuffer hexString = new StringBuffer();

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

String hex = Integer.toHexString(0xff & byteData[i]);

if(hex.length() == 1)

hexString.append("0");

hexString.append(hex);

}

return hexString.toString();

}catch(Exception ex){

ex.printStackTrace();

throw new RuntimeException();

}

}

}


사용 예 :



결과 :



반응형

+ Recent posts