RSAPrivateKey privKey = key.toRSAPrivateKey();
assertEquals(new Base64URL(n).decodeToBigInteger(), privKey.getModulus());
assertEquals(new Base64URL(d).decodeToBigInteger(), privKey.getPrivateExponent());
assertTrue(privKey instanceof RSAPrivateCrtKey);
RSAPrivateCrtKey privCrtKey = (RSAPrivateCrtKey)privKey;
assertEquals(new Base64URL(e).decodeToBigInteger(), privCrtKey.getPublicExponent());
assertEquals(new Base64URL(p).decodeToBigInteger(), privCrtKey.getPrimeP());
assertEquals(new Base64URL(q).decodeToBigInteger(), privCrtKey.getPrimeQ());
assertEquals(new Base64URL(dp).decodeToBigInteger(), privCrtKey.getPrimeExponentP());
assertEquals(new Base64URL(dq).decodeToBigInteger(), privCrtKey.getPrimeExponentQ());
assertEquals(new Base64URL(qi).decodeToBigInteger(), privCrtKey.getCrtCoefficient());
// Key pair export
KeyPair pair = key.toKeyPair();
RSAPublicKey pubKey = (RSAPublicKey)pair.getPublic();
assertEquals(new Base64URL(n).decodeToBigInteger(), pubKey.getModulus());
assertEquals(new Base64URL(e).decodeToBigInteger(), pubKey.getPublicExponent());
assertEquals("RSA", pubKey.getAlgorithm());
privKey = (RSAPrivateKey)pair.getPrivate();
assertEquals(new Base64URL(n).decodeToBigInteger(), privKey.getModulus());
assertEquals(new Base64URL(d).decodeToBigInteger(), privKey.getPrivateExponent());
assertTrue(privKey instanceof RSAPrivateCrtKey);
privCrtKey = (RSAPrivateCrtKey)privKey;
assertEquals(new Base64URL(e).decodeToBigInteger(), privCrtKey.getPublicExponent());
assertEquals(new Base64URL(p).decodeToBigInteger(), privCrtKey.getPrimeP());
assertEquals(new Base64URL(q).decodeToBigInteger(), privCrtKey.getPrimeQ());
assertEquals(new Base64URL(dp).decodeToBigInteger(), privCrtKey.getPrimeExponentP());
assertEquals(new Base64URL(dq).decodeToBigInteger(), privCrtKey.getPrimeExponentQ());
assertEquals(new Base64URL(qi).decodeToBigInteger(), privCrtKey.getCrtCoefficient());
// Key pair import, 1st private form
key = new RSAKey(pubKey, privKey, KeyUse.SIGNATURE, null, JWSAlgorithm.RS256, "1", null, null, null);
assertEquals(KeyUse.SIGNATURE, key.getKeyUse());