MessageDigest?Java?????????????,???????????????MessageDigest????????????:
import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class PasswordEncryption { public static String encryptPassword(String password) { try { MessageDigest md = MessageDigest.getInstance("SHA-256"); byte[] digest = md.digest(password.getBytes()); StringBuilder sb = new StringBuilder(); for (byte b : digest) { sb.append(String.format("x", b)); } return sb.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return null; } } public static void main(String[] args) { String password = "123456"; String encryptedPassword = encryptPassword(password); System.out.println("Encrypted password: " + encryptedPassword); } }
???????,????SHA-256?????????,???????????????????????????????????,??MD5?SHA-1?????????????????,????????????????????????????????????????????,??????????