如下所示 :
пакет cn.sunzn.md5; импортировать java.security.messagedigest; импорт java.security.nosuchalgorithmexception; public class str2md5 {public static void main (string [] args) {md5 ("sunzn"); } частная статическая строка md5 (string sourcestr) {string result = ""; try {messagegest md = messagedigest.getinstance ("md5"); md.update (sourcestr.getbytes ()); byte b [] = md.digest (); int i; StringBuffer buf = new StringBuffer (""); for (int offset = 0; offset <b.length; offset ++) {i = b [offset]; if (i <0) i += 256; if (i <16) buf.append ("0"); buf.append (integer.tohexstring (i)); } result = buf.toString (); System.out.println ("md5 (" + sourcestr + ", 32) =" + result); System.out.println ("md5 (" + sourcestr + ", 16) =" + buf.tostring (). Substring (8, 24)); } catch (nosuchalgorithmexception e) {System.out.println (e); } return Result; }}MD5 (Sunzn, 32) = 40379DB889F9124819228947FAAEB1F7MD5 (SUNZN, 16) = 89F9124819228947
以上就是小编为大家带来的 Java 编程下字符串的 16 位, 32 位 Md5 加密实现方法的全部内容了 , 希望对大家有所帮助 , 多多支持武林网 ~