code: public static JsonWebKey fromRSA(KeyPair keyPair) {
  
          RSAPrivateCrtKey privateKey = (RSAPrivateCrtKey) keyPair.getPrivate();
          JsonWebKey key = null;
  
          if (privateKey != null) {
  
              key = new JsonWebKey().withKty(JsonWebKeyType.RSA).withN(toByteArray(privateKey.getModulus()))
                      .withE(toByteArray(privateKey.getPublicExponent()))
                      .withD(toByteArray(privateKey.getPrivateExponent())).withP(toByteArray(privateKey.getPrimeP()))
                      .withQ(toByteArray(privateKey.getPrimeQ())).withDp(toByteArray(privateKey.getPrimeExponentP()))
                      .withDq(toByteArray(privateKey.getPrimeExponentQ()))
                      .withQi(toByteArray(privateKey.getCrtCoefficient()));
          } else {
  
              RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
  
              key = new JsonWebKey().withKty(JsonWebKeyType.RSA).withN(toByteArray(publicKey.getModulus()))
                      .withE(toByteArray(publicKey.getPublicExponent())).withD(null).withP(null).withQ(null).withDp(null)
                      .withDq(null).withQi(null);
          }
  
          return key;
      }
docs: Converts RSA key pair to JSON web key.
  
  @param keyPair
  RSA key pair
  @return the JSON web key, converted from RSA key pair.