@Test public void testLoadKey() { String keyFile = resolveFilename("key.pem.txt"); SslEngineFacadeFactory factory = new SslEngineFacadeFactory(); assertNotNull("Key was NULL", factory.readPrivateKey(keyFile, PASSWORD)); }
PrivateKey readPrivateKey(String pemFile, String password) { if (bouncyCastleSetupException != null) { throw new TransportException("BouncyCastle failed to load", bouncyCastleSetupException); } final Object pemObject = readPemObject(pemFile); PrivateKey privateKey = null; try { Object keyConverter = JcaPEMKeyConverterCons.newInstance(); setProvider(keyConverter, "BC"); if (PEMEncryptedKeyPairClass.isInstance(pemObject)) { Object decryptorBuilder = JcePEMDecryptorProviderBuilderCons.newInstance(); Object decryptProvider = builderMethod.invoke(decryptorBuilder, password.toCharArray()); Object decryptedKeyPair = decryptKeyPairMethod.invoke(pemObject, decryptProvider); KeyPair keyPair = (KeyPair) getKeyPairMethod.invoke(keyConverter, decryptedKeyPair); privateKey = keyPair.getPrivate(); } else if (PEMKeyPairClass.isInstance(pemObject)) { KeyPair keyPair = (KeyPair) getKeyPairMethod.invoke(keyConverter, pemObject); privateKey = keyPair.getPrivate(); } else if (PrivateKeyInfoClass.isInstance(pemObject)) { privateKey = (PrivateKey) getPrivateKeyMethod.invoke(keyConverter, pemObject); } else { final String msg = "Unable to load PrivateKey, Unpexected Object [" + pemObject.getClass().getName() + "]"; _logger.log(Level.SEVERE, msg); throw new TransportException(msg); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { final String msg = "Failed to process key file [" + pemFile + "] - " + e.getMessage(); throw new TransportException(msg, e); } return privateKey; }
SslEngineFacadeFactory { PrivateKey readPrivateKey(String pemFile, String password) { if (bouncyCastleSetupException != null) { throw new TransportException("BouncyCastle failed to load", bouncyCastleSetupException); } final Object pemObject = readPemObject(pemFile); PrivateKey privateKey = null; try { Object keyConverter = JcaPEMKeyConverterCons.newInstance(); setProvider(keyConverter, "BC"); if (PEMEncryptedKeyPairClass.isInstance(pemObject)) { Object decryptorBuilder = JcePEMDecryptorProviderBuilderCons.newInstance(); Object decryptProvider = builderMethod.invoke(decryptorBuilder, password.toCharArray()); Object decryptedKeyPair = decryptKeyPairMethod.invoke(pemObject, decryptProvider); KeyPair keyPair = (KeyPair) getKeyPairMethod.invoke(keyConverter, decryptedKeyPair); privateKey = keyPair.getPrivate(); } else if (PEMKeyPairClass.isInstance(pemObject)) { KeyPair keyPair = (KeyPair) getKeyPairMethod.invoke(keyConverter, pemObject); privateKey = keyPair.getPrivate(); } else if (PrivateKeyInfoClass.isInstance(pemObject)) { privateKey = (PrivateKey) getPrivateKeyMethod.invoke(keyConverter, pemObject); } else { final String msg = "Unable to load PrivateKey, Unpexected Object [" + pemObject.getClass().getName() + "]"; _logger.log(Level.SEVERE, msg); throw new TransportException(msg); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { final String msg = "Failed to process key file [" + pemFile + "] - " + e.getMessage(); throw new TransportException(msg, e); } return privateKey; } }
SslEngineFacadeFactory { PrivateKey readPrivateKey(String pemFile, String password) { if (bouncyCastleSetupException != null) { throw new TransportException("BouncyCastle failed to load", bouncyCastleSetupException); } final Object pemObject = readPemObject(pemFile); PrivateKey privateKey = null; try { Object keyConverter = JcaPEMKeyConverterCons.newInstance(); setProvider(keyConverter, "BC"); if (PEMEncryptedKeyPairClass.isInstance(pemObject)) { Object decryptorBuilder = JcePEMDecryptorProviderBuilderCons.newInstance(); Object decryptProvider = builderMethod.invoke(decryptorBuilder, password.toCharArray()); Object decryptedKeyPair = decryptKeyPairMethod.invoke(pemObject, decryptProvider); KeyPair keyPair = (KeyPair) getKeyPairMethod.invoke(keyConverter, decryptedKeyPair); privateKey = keyPair.getPrivate(); } else if (PEMKeyPairClass.isInstance(pemObject)) { KeyPair keyPair = (KeyPair) getKeyPairMethod.invoke(keyConverter, pemObject); privateKey = keyPair.getPrivate(); } else if (PrivateKeyInfoClass.isInstance(pemObject)) { privateKey = (PrivateKey) getPrivateKeyMethod.invoke(keyConverter, pemObject); } else { final String msg = "Unable to load PrivateKey, Unpexected Object [" + pemObject.getClass().getName() + "]"; _logger.log(Level.SEVERE, msg); throw new TransportException(msg); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { final String msg = "Failed to process key file [" + pemFile + "] - " + e.getMessage(); throw new TransportException(msg, e); } return privateKey; } SslEngineFacadeFactory(); }
SslEngineFacadeFactory { PrivateKey readPrivateKey(String pemFile, String password) { if (bouncyCastleSetupException != null) { throw new TransportException("BouncyCastle failed to load", bouncyCastleSetupException); } final Object pemObject = readPemObject(pemFile); PrivateKey privateKey = null; try { Object keyConverter = JcaPEMKeyConverterCons.newInstance(); setProvider(keyConverter, "BC"); if (PEMEncryptedKeyPairClass.isInstance(pemObject)) { Object decryptorBuilder = JcePEMDecryptorProviderBuilderCons.newInstance(); Object decryptProvider = builderMethod.invoke(decryptorBuilder, password.toCharArray()); Object decryptedKeyPair = decryptKeyPairMethod.invoke(pemObject, decryptProvider); KeyPair keyPair = (KeyPair) getKeyPairMethod.invoke(keyConverter, decryptedKeyPair); privateKey = keyPair.getPrivate(); } else if (PEMKeyPairClass.isInstance(pemObject)) { KeyPair keyPair = (KeyPair) getKeyPairMethod.invoke(keyConverter, pemObject); privateKey = keyPair.getPrivate(); } else if (PrivateKeyInfoClass.isInstance(pemObject)) { privateKey = (PrivateKey) getPrivateKeyMethod.invoke(keyConverter, pemObject); } else { final String msg = "Unable to load PrivateKey, Unpexected Object [" + pemObject.getClass().getName() + "]"; _logger.log(Level.SEVERE, msg); throw new TransportException(msg); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { final String msg = "Failed to process key file [" + pemFile + "] - " + e.getMessage(); throw new TransportException(msg, e); } return privateKey; } SslEngineFacadeFactory(); ProtonSslEngine createProtonSslEngine(SslDomain domain, SslPeerDetails peerDetails); void resetCache(); }
SslEngineFacadeFactory { PrivateKey readPrivateKey(String pemFile, String password) { if (bouncyCastleSetupException != null) { throw new TransportException("BouncyCastle failed to load", bouncyCastleSetupException); } final Object pemObject = readPemObject(pemFile); PrivateKey privateKey = null; try { Object keyConverter = JcaPEMKeyConverterCons.newInstance(); setProvider(keyConverter, "BC"); if (PEMEncryptedKeyPairClass.isInstance(pemObject)) { Object decryptorBuilder = JcePEMDecryptorProviderBuilderCons.newInstance(); Object decryptProvider = builderMethod.invoke(decryptorBuilder, password.toCharArray()); Object decryptedKeyPair = decryptKeyPairMethod.invoke(pemObject, decryptProvider); KeyPair keyPair = (KeyPair) getKeyPairMethod.invoke(keyConverter, decryptedKeyPair); privateKey = keyPair.getPrivate(); } else if (PEMKeyPairClass.isInstance(pemObject)) { KeyPair keyPair = (KeyPair) getKeyPairMethod.invoke(keyConverter, pemObject); privateKey = keyPair.getPrivate(); } else if (PrivateKeyInfoClass.isInstance(pemObject)) { privateKey = (PrivateKey) getPrivateKeyMethod.invoke(keyConverter, pemObject); } else { final String msg = "Unable to load PrivateKey, Unpexected Object [" + pemObject.getClass().getName() + "]"; _logger.log(Level.SEVERE, msg); throw new TransportException(msg); } } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { final String msg = "Failed to process key file [" + pemFile + "] - " + e.getMessage(); throw new TransportException(msg, e); } return privateKey; } SslEngineFacadeFactory(); ProtonSslEngine createProtonSslEngine(SslDomain domain, SslPeerDetails peerDetails); void resetCache();  }