자바 hashHmacSha1()

(Java hashHmacSha1()에서 넘어옴)

1 개요[ | ]

Java hashHmacSha1()
public static String hashHmacSha1(String value, String key) {
	try {
		byte[] hexBytes = new Hex().encode(hashHmacSha1Raw(value,key));
		return new String(hexBytes, "UTF-8");
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
public static byte[] hashHmacSha1Raw(String value, String key) {
	try {
		byte[] keyBytes = key.getBytes();           
		SecretKeySpec signingKey = new SecretKeySpec(keyBytes, "HmacSHA1");
		Mac mac = Mac.getInstance("HmacSHA1");
		mac.init(signingKey);
		return mac.doFinal(value.getBytes());
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
public static void main(String[] args) {
	System.out.println( hashHmacSha1( "hello world", "secret" ) );
	// 03376ee7ad7bbfceee98660439a4d8b125122a5a
	System.out.println( new String(hashHmacSha1Raw( "hello world", "secret" )) );
	// �7n�{���f�9�ر%�*Z
}

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}