"자바 hashHmacSha1()"의 두 판 사이의 차이

4번째 줄: 4번째 줄:
public static String hashHmacSha1(String value, String key) {
public static String hashHmacSha1(String value, String key) {
try {
try {
byte[] hexBytes = (byte[]) new Hex().encode(hashHmacSha1Raw(value,key));
byte[] hexBytes = new Hex().encode(hashHmacSha1Raw(value,key));
return new String(hexBytes, "UTF-8");
return new String(hexBytes, "UTF-8");
} catch (Exception e) {
} catch (Exception e) {

2017년 4월 13일 (목) 18:42 판

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 }}