You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constcrypto=require('crypto');constkey='secret key';constdata='data data data data data data data data data data data';consthmac=crypto.createHmac('sha1',key);hmac.update(data);conststr=hmac.digest('base64');console.log(`result : ${str}`);// result : GWf8CRCtvePYZPxjTFqUsIoueKo=
node.js crypto모듈 사용
java
@Testpublicvoidtest() throwsNoSuchAlgorithmException, InvalidKeyException, UnsupportedEncodingException {
Stringkey = "secret key";
Stringdata = "data data data data data data data data data data data";
finalStringHMAC_SHA1_ALGORITHM = "HmacSHA1";
Macmac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
mac.init(newSecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM));
mac.update(data.getBytes(StandardCharsets.UTF_8.name()));
Stringstr = Base64.encodeBase64String(mac.doFinal());
System.out.println(String.format("result : %s", str)); // result : GWf8CRCtvePYZPxjTFqUsIoueKo=
}