md5的java实现


public class MD5Util {
	public final static String getMD5(String s) {
		char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
		MessageDigest messageDigest = null;
		try {
			messageDigest = MessageDigest.getInstance("MD5");
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		messageDigest.update(s.getBytes());
		byte[] md = messageDigest.digest();
		char str[] = new char[md.length * 2];
		int k = 0;
		for (int i = 0; i < md.length; i++) {
			byte byte0 = md[i];
			str[k++] = hexDigits[byte0 >>> 4 & 0xf];
			str[k++] = hexDigits[byte0 & 0xf];
		}
		return new String(str);
	}
}


你可能感兴趣的:(java,C++,c,C#,F#)