如何使用 .crt 证书和 public .key 令牌发送带有 Rest Assured 的 HTTPS 请求

How to send HTTPS request with Rest Assured using .crt certificate and public .key token

我需要发送带有客户端 .crt 证书和 public 密钥 .key 的 REST 保证的 https 请求 如果我的证书和项目中的密钥像

,我该如何发送请求
"src/test/resources/certificate.crt"
"src/test/resources/key.key"
 String response = RestAssured
        .given()
        .trustStore("src/test/resources/certificate.crt", "paasword")
        .when()
        .contentType(MediaType.APPLICATION_JSON)
        .accept(MediaType.APPLICATION_JSON)
        .header("Authorization", authHeader)
        .baseUri("https://server.us.oracle.com:55898")
        .queryParam("name", args)
        .get("/validendpoint").prettyPrint();
String clientCertificatePath = "certs/ClientCertificate.p12";
String trustStorePath = "C:/Program Files/Java/jre1.8.0_91/lib/security/cacerts";
String trustStorePassword = "changeit"; // default trust store password

KeyStore clientStore = KeyStore.getInstance("PKCS12");
clientStore.load(new FileInputStream(clientCertificatePath), clientPassword.toCharArray());

KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(clientStore, clientPassword.toCharArray());
KeyManager[] kms = kmf.getKeyManagers();

KeyStore trustStore = KeyStore.getInstance("JKS");
trustStore.load(new FileInputStream(trustStorePath), trustStorePassword.toCharArray());

TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
tmf.init(trustStore);
TrustManager[] tms = tmf.getTrustManagers();

SSLContext sslContext = null;
sslContext = SSLContext.getInstance("TLS");
sslContext.init(kms, tms, new SecureRandom());

SSLSocketFactory lSchemeSocketFactory=null;

lSchemeSocketFactory = new SSLSocketFactory(clientStore, clientPassword, trustStore);

// configure Rest Assured
RestAssured.config = RestAssured.config().sslConfig(sslConfig().with().sslSocketFactory(lSchemeSocketFactory).and().allowAllHostnames());