MD5(Message-Digest Algorithm 5)????????????,???????????(digest)????????????128???????,???32??????
MD5?????????:
- ??????????512?(64???)????????
- ???????????????????,??????????????,???????????????
- ???????64?????,?????????????,?????????????
- ?????????????MD5???
Java?????java.security.MessageDigest????MD5???????????Java????:
import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class MD5Example { public static void main(String[] args) { String input = "Hello, MD5!"; try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(input.getBytes()); byte[] digest = md.digest(); StringBuilder sb = new StringBuilder(); for (byte b : digest) { sb.append(String.format("x", b & 0xff)); } System.out.println("MD5 hash: " + sb.toString()); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } } }
??????,????????MD5??????,MD5???????????,????????,????????????,?SHA-256??