JoseUtils { public static String macKeyAlgorithm(SecretKey macKey) { if (!"HMAC".equals(macKey.getAlgorithm())) { throw new IllegalArgumentException("Bad algorithm: " + macKey.getAlgorithm()); } int size = macKey.getEncoded().length * 8; switch (size) { case 256: return AlgorithmIdentifiers.HMAC_SHA256; case 384: return AlgorithmIdentifiers.HMAC_SHA384; case 512: return AlgorithmIdentifiers.HMAC_SHA512; default: throw new IllegalArgumentException("Bad key size: " + size); } } private  JoseUtils(); static JSONBuilder createJoseRequest(URL url, KeyPair keypair,
                @Nullable JSONBuilder payload, @Nullable String nonce, @Nullable String kid); static Map<String, Object> createExternalAccountBinding(String kid,
            PublicKey accountKey, SecretKey macKey, URL resource); static Map<String, Object> publicKeyToJWK(PublicKey key); static PublicKey jwkToPublicKey(Map<String, Object> jwk); static byte[] thumbprint(PublicKey key); static String keyAlgorithm(JsonWebKey jwk); static String macKeyAlgorithm(SecretKey macKey);  }
@Test public void testMacKey() throws Exception { assertThat(JoseUtils.macKeyAlgorithm(TestUtils.createSecretKey("SHA-256")), is("HS256")); assertThat(JoseUtils.macKeyAlgorithm(TestUtils.createSecretKey("SHA-384")), is("HS384")); assertThat(JoseUtils.macKeyAlgorithm(TestUtils.createSecretKey("SHA-512")), is("HS512")); }