?????Java???????????,????????????????????????
- ???????:??????????????????????????,??????????????,?????????????????????,??????????????????????,???????????????????????,????????????????
- ????:????????,?????????????????????????????????,??????????????????,????????????????????,??????????????????,??????????????????????????,???????
- ????:???????????????????????,??????SSL/TLS??????,?????????????,????????????????,????????????
?Java?,????java.security.MessageDigest
??????????????????,???????SHA-256?????????????:
import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class HashExample { public static void main(String[] args) { String input = "Hello, world!"; try { MessageDigest md = MessageDigest.getInstance("SHA-256"); byte[] hashBytes = md.digest(input.getBytes(StandardCharsets.UTF_8)); StringBuilder sb = new StringBuilder(); for (byte b : hashBytes) { sb.append(String.format("x", b)); } System.out.println("Hash: " + sb.toString()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } } }
??????????MessageDigest
??,????SHA-256???????,?????????????,???digest()
??????????,????????????????????