MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / computeHmac

Method computeHmac

CodenameOne/src/com/codename1/security/Jwt.java:309–325  ·  view source on GitHub ↗
(String algorithm, byte[] secret, String signingInput)

Source from the content-addressed store, hash-verified

307 }
308
309 private static byte[] computeHmac(String algorithm, byte[] secret, String signingInput) {
310 String hashAlg;
311 if (HS256.equals(algorithm)) {
312 hashAlg = Hash.SHA256;
313 } else if (HS384.equals(algorithm)) {
314 hashAlg = Hash.SHA384;
315 } else if (HS512.equals(algorithm)) {
316 hashAlg = Hash.SHA512;
317 } else {
318 throw new CryptoException("unsupported HMAC algorithm: " + algorithm);
319 }
320 try {
321 return Hmac.create(hashAlg, secret).doFinal(signingInput.getBytes("UTF-8"));
322 } catch (UnsupportedEncodingException e) {
323 throw new CryptoException("UTF-8 not supported", e);
324 }
325 }
326
327 private static String signatureAlgorithmFor(String jwtAlg) {
328 if (RS256.equals(jwtAlg)) {

Callers 2

signMethod · 0.95
verifyHmacMethod · 0.95

Calls 4

createMethod · 0.95
doFinalMethod · 0.80
equalsMethod · 0.65
getBytesMethod · 0.65

Tested by

no test coverage detected