Here you can find the source of sha256(String src)
Parameter | Description |
---|---|
src | a string to digest |
public static String sha256(String src)
//package com.java2s; //License from project: Apache License import java.math.BigInteger; import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { private static MessageDigest md; /**//from w w w . ja v a 2s . c o m * Calculates the SHA-256 digest and returns the value as a 64 character hex * string. * * @param src * a string to digest * @return SHA-256 digest as a hex string */ public static String sha256(String src) { try { md = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } md.update(src.getBytes(StandardCharsets.UTF_8)); return String.format("%064x", new BigInteger(1, md.digest())); } }