标签:加密 package import public md5算法实现
package com.asiainfo.encryption.s1; import java.security.MessageDigest; public class Md5 { public static void main(String[] args) { try { String str = "简单加密"; MessageDigest messageDigest = MessageDigest.getInstance("MD5"); messageDigest.update(str.getBytes()); byte[] hash = messageDigest.digest(); StringBuffer hexString = new StringBuffer(); for (int i = 0; i < hash.length; i++) { if ((0xff & hash[i]) < 0x10) { hexString.append("0" + Integer.toHexString((0xFF & hash[i]))); } else { hexString.append(Integer.toHexString(0xFF & hash[i])); } } System.out.println("result: " + hexString); } catch (Exception e) { e.printStackTrace(); } } }
result: aaf4b26fcb652b9d6b9deec186cb21aa
本文出自 “一代宗师” 博客,请务必保留此出处http://765682.blog.51cto.com/755682/1854052
标签:加密 package import public md5算法实现
原文地址:http://765682.blog.51cto.com/755682/1854052