web tools

服务网址:http://webtools.kimnote.com/

提供在线编码转换,

在线 url encode、decode,

在线base64 encode、decode,

在线md5、sha1、sha256、sha512 加密,

在线html entity escape、unescape,

提供在线UTF-8,GB2312,Big5,EUC-KR,EUC-JP,GB18030,GBK,ISO-8859-1,Shift_JIS,US-ASCII,UTF-16的编码转换

我把EncryptUtil的代码参考如下:

import java.security.MessageDigest;

/**
 * @author jongsuny
 */
public class EncryptUtil {
	private static final char[] HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
	private static String getFormattedText(byte[] bytes) {
		int len = bytes.length;
		StringBuilder buf = new StringBuilder(len * 2);
		// 把密文转换成十六进制的字符串形式
		for (int j = 0; j < len; j++) { 			buf.append(HEX_DIGITS[(bytes[j] >> 4) & 0x0f]);
			buf.append(HEX_DIGITS[bytes[j] & 0x0f]);
		}
		return buf.toString();
	}
	public static String encodeMD516(String text){
		String res = encodeMD5(text); 
		return  res == null ? null : res.substring(8, 24);
	}
	public static String encodeMD5(String text) {
		if (text == null) {
			return null;
		}
		try {
			MessageDigest messageDigest = MessageDigest.getInstance("md5");
			messageDigest.update(text.getBytes());
			return getFormattedText(messageDigest.digest());
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

	public static String encodeSha1(String text) {
		if (text == null) {
			return null;
		}
		try {
			MessageDigest messageDigest = MessageDigest.getInstance("sha-1");
			messageDigest.update(text.getBytes());
			return getFormattedText(messageDigest.digest());
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	public static String encodeSha224(String text) {
		if (text == null) {
			return null;
		}
		try {
			MessageDigest messageDigest = MessageDigest.getInstance("sha-224");
			messageDigest.update(text.getBytes());
			return getFormattedText(messageDigest.digest());
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	public static String encodeSha256(String text) {
		if (text == null) {
			return null;
		}
		try {
			MessageDigest messageDigest = MessageDigest.getInstance("sha-256");
			messageDigest.update(text.getBytes());
			return getFormattedText(messageDigest.digest());
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	public static String encodeSha384(String text) {
		if (text == null) {
			return null;
		}
		try {
			MessageDigest messageDigest = MessageDigest.getInstance("sha-384");
			messageDigest.update(text.getBytes());
			return getFormattedText(messageDigest.digest());
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	public static String encodeSha512(String text) {
		if (text == null) {
			return null;
		}
		try {
			MessageDigest messageDigest = MessageDigest.getInstance("sha-512");
			messageDigest.update(text.getBytes());
			return getFormattedText(messageDigest.digest());
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	public static void main(String[] args) {
		String text = "test";
		System.out.println("md516(test) = "+encodeMD516(text));
		System.out.println("md5(test) = "+encodeMD5(text));
		System.out.println("sha1(test) = "+encodeSha1(text));
		System.out.println("sha256(test) = "+encodeSha256(text));
		System.out.println("sha384(test) = "+encodeSha384(text));
		System.out.println("sha512(test) = "+encodeSha512(text));
	}
}

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>