on
Java HMAC 암호화
Java HMAC 암호화
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
javajavjimport javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; public class HMacSha256 { public static void main( String [] args) { String message = "ABCDEFGHIJKLMNOP" ; String key = "hmacTest" ; String algorithm = "HmacSHA256" ; //HmacMD5,HmacSHA1,HmacSHA224,HmacSHA384,HmacSHA512 try { System . out . println (Hmac(key,message,algorithm)); } catch (Exception e) { e.printStackTrace(); } } public static String Hmac( String key, String message, String algorithm) throws Exception { Mac hasher = Mac.getInstance(algorithm); hasher.init( new SecretKeySpec(key.getBytes( "utf-8" ), algorithm)); byte [] hash = hasher.doFinal(message.getBytes()); return Base64.encodeBase64String(hash); } } Colored by Color Scripter
from http://devhj.tistory.com/20 by ccl(A) rewrite - 2021-12-15 18:01:34