1. 程式人生 > >SHA-1加密

SHA-1加密

import java.security.MessageDigest;

import org.apache.commons.codec.binary.Hex;

public class Sha1_Util {
	
	/**
	 * SHA-1加密
	 * @param value
	 * @return
	 */
	public static String hexSHA1(String value) {
		try {
			MessageDigest md = MessageDigest.getInstance("SHA-1");
			md.update(value.getBytes("utf-8"));
			byte[] digest = md.digest();
			return byteToHexString(digest);
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}
	}
	
	public static String byteToHexString(byte[] bytes) {
		return String.valueOf(Hex.encodeHex(bytes));
	}

}