@Test
  public void exportToJavaRSAKey() throws Exception {
    KeysetHandle privateHandle =
        KeysetHandle.generateNew(KeyTemplates.get("RSA_SSA_PKCS1_3072_SHA256_F4_RAW"));
    KeysetHandle publicHandle = privateHandle.getPublicKeysetHandle();

    PublicKeySign signer = privateHandle.getPrimitive(PublicKeySign.class);
    byte[] data = "data".getBytes(UTF_8);
    byte[] sig = signer.sign(data);

    // Export private key and sign using java.security.Signature.
    RsaSsaPkcs1PrivateKey rsaSsaPkcs1PrivateKey =
        (RsaSsaPkcs1PrivateKey) privateHandle.getAt(0).getKey();
    PrivateKey privateKey =
        KeyFactory.getInstance("RSA")
            .generatePrivate(
                new RSAPrivateCrtKeySpec(
                    rsaSsaPkcs1PrivateKey.getPublicKey().getModulus(),
                    rsaSsaPkcs1PrivateKey.getParameters().getPublicExponent(),
                    rsaSsaPkcs1PrivateKey
                        .getPrivateExponent()
                        .getBigInteger(InsecureSecretKeyAccess.get()),
                    rsaSsaPkcs1PrivateKey.getPrimeP().getBigInteger(InsecureSecretKeyAccess.get()),
                    rsaSsaPkcs1PrivateKey.getPrimeQ().getBigInteger(InsecureSecretKeyAccess.get()),
                    rsaSsaPkcs1PrivateKey
                        .getPrimeExponentP()
                        .getBigInteger(InsecureSecretKeyAccess.get()),
                    rsaSsaPkcs1PrivateKey
                        .getPrimeExponentQ()
                        .getBigInteger(InsecureSecretKeyAccess.get()),
                    rsaSsaPkcs1PrivateKey
                        .getCrtCoefficient()
                        .getBigInteger(InsecureSecretKeyAccess.get())));
    Signature signatureSigner = Signature.getInstance("SHA256withRSA");
    signatureSigner.initSign(privateKey);
    signatureSigner.update(data);
    // These signatures are deterministic, so they must be equal.
    assertThat(signatureSigner.sign()).isEqualTo(sig);

    // Export public key and verify using java.security.Signature.
    RsaSsaPkcs1PublicKey rsaSsaPkcs1PublicKey =
        (RsaSsaPkcs1PublicKey) publicHandle.getAt(0).getKey();
    PublicKey publicKey =
        KeyFactory.getInstance("RSA")
            .generatePublic(
                new RSAPublicKeySpec(
                    rsaSsaPkcs1PublicKey.getModulus(),
                    rsaSsaPkcs1PublicKey.getParameters().getPublicExponent()));
    Signature signatureVerify = Signature.getInstance("SHA256withRSA");
    signatureVerify.initVerify(publicKey);
    signatureVerify.update(data);
    assertThat(signatureVerify.verify(sig)).isTrue();
  }
This test shows how Tink keys can be exported to Java RSA keys.
java_src/src/test/java/com/google/crypto/tink/signature/KeyConversionTest.java