@Test public void testCalculate() { assertEquals("dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk", sHmacImpl.calculate(TokenDecoder.base64Encode(hs256), TokenDecoder.base64Encode(payload), key)); }
@Override public String calculate(String header, String payload, SymmetricKeyImpl signingKey) { StringBuilder sb = new StringBuilder(); sb.append(header).append(".").append(payload); String stringToSign = sb.toString(); byte[] bytes = stringToSign.getBytes(); try { Mac mac = Mac.getInstance("HMACSHA256"); mac.init(new SecretKeySpec(signingKey.getKey(), mac.getAlgorithm())); mac.update(bytes); bytes = mac.doFinal(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } catch (InvalidKeyException e) { throw new RuntimeException(e); } return TokenDecoder.base64Encode(bytes); }
SignatureMethodsHMAC256Impl implements SignatureMethod<SymmetricKeyImpl, SymmetricKeyImpl> { @Override public String calculate(String header, String payload, SymmetricKeyImpl signingKey) { StringBuilder sb = new StringBuilder(); sb.append(header).append(".").append(payload); String stringToSign = sb.toString(); byte[] bytes = stringToSign.getBytes(); try { Mac mac = Mac.getInstance("HMACSHA256"); mac.init(new SecretKeySpec(signingKey.getKey(), mac.getAlgorithm())); mac.update(bytes); bytes = mac.doFinal(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } catch (InvalidKeyException e) { throw new RuntimeException(e); } return TokenDecoder.base64Encode(bytes); } }
SignatureMethodsHMAC256Impl implements SignatureMethod<SymmetricKeyImpl, SymmetricKeyImpl> { @Override public String calculate(String header, String payload, SymmetricKeyImpl signingKey) { StringBuilder sb = new StringBuilder(); sb.append(header).append(".").append(payload); String stringToSign = sb.toString(); byte[] bytes = stringToSign.getBytes(); try { Mac mac = Mac.getInstance("HMACSHA256"); mac.init(new SecretKeySpec(signingKey.getKey(), mac.getAlgorithm())); mac.update(bytes); bytes = mac.doFinal(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } catch (InvalidKeyException e) { throw new RuntimeException(e); } return TokenDecoder.base64Encode(bytes); }  }
SignatureMethodsHMAC256Impl implements SignatureMethod<SymmetricKeyImpl, SymmetricKeyImpl> { @Override public String calculate(String header, String payload, SymmetricKeyImpl signingKey) { StringBuilder sb = new StringBuilder(); sb.append(header).append(".").append(payload); String stringToSign = sb.toString(); byte[] bytes = stringToSign.getBytes(); try { Mac mac = Mac.getInstance("HMACSHA256"); mac.init(new SecretKeySpec(signingKey.getKey(), mac.getAlgorithm())); mac.update(bytes); bytes = mac.doFinal(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } catch (InvalidKeyException e) { throw new RuntimeException(e); } return TokenDecoder.base64Encode(bytes); }  @Override String calculate(String header, String payload, SymmetricKeyImpl signingKey); @Override boolean verify(String signature, String header, String payload, SymmetricKeyImpl verifyingKey); @Override String getAlgorithm(); }
SignatureMethodsHMAC256Impl implements SignatureMethod<SymmetricKeyImpl, SymmetricKeyImpl> { @Override public String calculate(String header, String payload, SymmetricKeyImpl signingKey) { StringBuilder sb = new StringBuilder(); sb.append(header).append(".").append(payload); String stringToSign = sb.toString(); byte[] bytes = stringToSign.getBytes(); try { Mac mac = Mac.getInstance("HMACSHA256"); mac.init(new SecretKeySpec(signingKey.getKey(), mac.getAlgorithm())); mac.update(bytes); bytes = mac.doFinal(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } catch (InvalidKeyException e) { throw new RuntimeException(e); } return TokenDecoder.base64Encode(bytes); }  @Override String calculate(String header, String payload, SymmetricKeyImpl signingKey); @Override boolean verify(String signature, String header, String payload, SymmetricKeyImpl verifyingKey); @Override String getAlgorithm();  }