All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.kukababy.utils.MD5 Maven / Gradle / Ivy

The newest version!
package com.kukababy.utils;

import java.security.MessageDigest;

/**
 * @describe 描述
 * @author 老汪 [email protected]
 * @date 创建时间:2015年4月28日 下午5:08:42
 * 
 */
public class MD5 {
	final static char hexChars[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

	public static String convert(String s) {
		try {
			byte[] bytes = s.getBytes();
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(bytes);
			bytes = md.digest();
			int j = bytes.length;
			char[] chars = new char[j * 2];
			int k = 0;
			for (int i = 0; i < bytes.length; i++) {
				byte b = bytes[i];
				chars[k++] = hexChars[b >>> 4 & 0xf];
				chars[k++] = hexChars[b & 0xf];
			}
			return new String(chars);
		} catch (Exception e) {
			return null;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy