import java.security.MessageDigest; public class CommonUtils { public static String SHA256Encoder(String password) { try{ MessageDigest digest = MessageDigest.getInstance("SHA-256"); byte[] hash = digest.digest(password.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.toLowerCase()); } return hexString.toString(); } catch(Exception e){ e.printStackTrace(); throw new RuntimeException(e); } } } | cs |
Java