public void testFullConstructorAndSerialization()
throws Exception {
URL x5u = new URL("http://example.com/jwk.json");
Base64URL x5t = new Base64URL("abc");
List<Base64> x5c = new LinkedList<Base64>();
x5c.add(new Base64("def"));
RSAKey key = new RSAKey(new Base64URL(n), new Base64URL(e), new Base64URL(d),
new Base64URL(p), new Base64URL(q),
new Base64URL(dp), new Base64URL(dq), new Base64URL(qi),
null,
KeyUse.SIGNATURE, null, JWSAlgorithm.RS256, "1",
x5u, x5t, x5c);
// Test getters
assertEquals(KeyUse.SIGNATURE, key.getKeyUse());
assertNull(key.getKeyOperations());
assertEquals(JWSAlgorithm.RS256, key.getAlgorithm());
assertEquals("1", key.getKeyID());
assertEquals(x5u.toString(), key.getX509CertURL().toString());
assertEquals(x5t.toString(), key.getX509CertThumbprint().toString());
assertEquals(x5c.size(), key.getX509CertChain().size());
assertEquals(new Base64URL(n), key.getModulus());
assertEquals(new Base64URL(e), key.getPublicExponent());
assertEquals(new Base64URL(d), key.getPrivateExponent());
assertEquals(new Base64URL(p), key.getFirstPrimeFactor());
assertEquals(new Base64URL(q), key.getSecondPrimeFactor());
assertEquals(new Base64URL(dp), key.getFirstFactorCRTExponent());
assertEquals(new Base64URL(dq), key.getSecondFactorCRTExponent());
assertEquals(new Base64URL(qi), key.getFirstCRTCoefficient());
assertTrue(key.getOtherPrimes().isEmpty());
assertTrue(key.isPrivate());
String jwkString = key.toJSONObject().toString();
key = RSAKey.parse(jwkString);
// Test getters
assertEquals(KeyUse.SIGNATURE, key.getKeyUse());
assertNull(key.getKeyOperations());
assertEquals(JWSAlgorithm.RS256, key.getAlgorithm());
assertEquals("1", key.getKeyID());
assertEquals(x5u.toString(), key.getX509CertURL().toString());
assertEquals(x5t.toString(), key.getX509CertThumbprint().toString());
assertEquals(x5c.size(), key.getX509CertChain().size());
assertEquals(new Base64URL(n), key.getModulus());
assertEquals(new Base64URL(e), key.getPublicExponent());
assertEquals(new Base64URL(d), key.getPrivateExponent());
assertEquals(new Base64URL(p), key.getFirstPrimeFactor());
assertEquals(new Base64URL(q), key.getSecondPrimeFactor());
assertEquals(new Base64URL(dp), key.getFirstFactorCRTExponent());
assertEquals(new Base64URL(dq), key.getSecondFactorCRTExponent());
assertEquals(new Base64URL(qi), key.getFirstCRTCoefficient());
assertTrue(key.getOtherPrimes().isEmpty());
assertTrue(key.isPrivate());
// Test conversion to public JWK
key = key.toPublicJWK();
assertEquals(KeyUse.SIGNATURE, key.getKeyUse());
assertNull(key.getKeyOperations());
assertEquals(JWSAlgorithm.RS256, key.getAlgorithm());
assertEquals("1", key.getKeyID());
assertEquals(new Base64URL(n), key.getModulus());
assertEquals(new Base64URL(e), key.getPublicExponent());
assertNull(key.getPrivateExponent());
assertNull(key.getFirstPrimeFactor());
assertNull(key.getSecondPrimeFactor());