作者:4号的国哥 | 来源:互联网 | 2023-09-11 18:02
MD5加密:
加密后的结果为:
try {String password = vo.getPassword();MessageDigest md = MessageDigest.getInstance("md5");byte[] bytes = md.digest(password.getBytes());String str = Base64.getEncoder().encodeToString(bytes);vo.setPassword(str);} catch (NoSuchAlgorithmException e) {e.printStackTrace();}
SHA加密(安全性更高)
try {String password = vo.getPassword();MessageDigest md = MessageDigest.getInstance("SHA");md.update(password.getBytes());String str = new BigInteger(md.digest()).toString(32);vo.setPassword(str);System.out.println(str);} catch (NoSuchAlgorithmException e) {e.printStackTrace();}