java32至md5加密
码,如以下
<span style="font-size:18px;">import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public class Main { public static void main(String[] args) { Main Main = new Main(); System.out.println(Main.encryption("xiaowen123")); } /** * * @param plainText * 明文 * @return 32位密文 */ public String encryption(String plainText) { String md5 = new String(); try { MessageDigest md = MessageDigest.getInstance("MD5"); md.update(plainText.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)); } md5 = buf.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return md5; } }</span>
具体地址:http://java.662p.com/thread-3792-1-1.html
版权声明:本文博客原创文章,博客,未经同意,不得转载。