/** * Loads a public-private key pair * * @param keystoreFile * @param keystorePassword * @param publicKeyAlias * @return */ public static KeyPair loadKeyPair( String keystoreFile, String keystorePassword, String publicKeyAlias ) { KeyStore keystore = loadKeystore(keystoreFile, keystorePassword); PublicKey publicKey = loadPublicKey(keystore, publicKeyAlias); PrivateKey privateKey = loadPrivateKey(keystore, keystorePassword, publicKeyAlias); return new KeyPair(publicKey, privateKey); }
private byte[] getPrivateKeyContent() throws Exception { try { KeyStore keyStore = SslUtils.loadKeystore(keyStoreFile, keyStorePassword); PrivateKey privateKey = (PrivateKey) keyStore.getKey(keyAlias, null); if (privateKey == null) { throw new Exception("The alias '" + keyAlias + "' does not point to an existing key-related entry"); } StringWriter stringWriter = new StringWriter(); PEMWriter pemWriter = new PEMWriter(stringWriter); pemWriter.writeObject(privateKey); pemWriter.close(); byte[] privateKeyPEM = stringWriter.toString().getBytes(); return privateKeyPEM; } catch (Exception e) { throw new Exception("Could not get private key content", e); } }
KeyStore trustStore = SslUtils.loadKeystore(truststoreFile, truststorePassword); List<Certificate> certificates = new ArrayList<Certificate>();
clientSSLKeyStore = SslUtils.loadKeystore(clientSSLCertificateP12File.getAbsolutePath(), password); fis = new FileInputStream(clientSSLCertificateP12File);
sslContextBuilder.loadKeyMaterial(SslUtils.loadKeystore(keyStoreFile, keyStorePassword), keyStorePassword.toCharArray()); KeyStore trustStore = SslUtils.loadKeystore(trustStoreFile, trustStorePassword);
KeyStore trustStore = SslUtils.loadKeystore(trustStoreFile, trustStorePassword);