public static PrivateKey readPrivateKey(File keyFile) throws InvalidKeySpecException, NoSuchAlgorithmException, IOException { byte[] priv = FileUtil.readFile(keyFile); return readPrivateKey(priv); }
private static KeyStore getKeyStore(File certFile, File keyFile) { try { PrivateKey pk = readPrivateKey(keyFile); Certificate[] chain = readCertificateChain(certFile); return getKeyStore(chain, pk); } catch (InvalidKeySpecException ex) { throw new RuntimeException("failed to read RSA private key from " + keyFile, ex); } catch (NoSuchAlgorithmException ex) { throw new RuntimeException("BUG: failed to create empty KeyStore", ex); } catch (FileNotFoundException ex) { throw new RuntimeException("failed to find certificate and/or key file " + certFile + "," + keyFile, ex); } catch (IOException ex) { throw new RuntimeException("failed to read certificate file " + certFile, ex); } catch (CertificateException ex) { throw new RuntimeException("failed to load certificate from file " + certFile, ex); } }
public static Subject createSubject(File certFile, File keyFile) { try { PrivateKey pk = readPrivateKey(keyFile); X509Certificate[] chain = readCertificateChain(certFile); return AuthenticationUtil.getSubject(chain, pk); } catch (InvalidKeySpecException ex) { throw new RuntimeException("failed to read RSA private key from " + keyFile, ex); } catch (NoSuchAlgorithmException ex) { throw new RuntimeException("BUG: failed to create empty KeyStore", ex); } catch (FileNotFoundException ex) { throw new RuntimeException("failed to find certificate and/or key file " + certFile + "," + keyFile, ex); } catch (IOException ex) { throw new RuntimeException("failed to read certificate file " + certFile, ex); } catch (CertificateException ex) { throw new RuntimeException("failed to load certificate from file " + certFile, ex); } }