(String alias, File file,
char[] pwd)
| 1089 | } |
| 1090 | |
| 1091 | public static final KeyPair readKeyPairFromFile(String alias, File file, |
| 1092 | char[] pwd) { |
| 1093 | FileInputStream input = null; |
| 1094 | try { |
| 1095 | KeyStore keyStore = KeyStore.getInstance("PKCS12"); |
| 1096 | input = new FileInputStream(file); |
| 1097 | keyStore.load(new FileInputStream(file), pwd); |
| 1098 | input.close(); |
| 1099 | |
| 1100 | KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry) keyStore |
| 1101 | .getEntry(alias, new KeyStore.PasswordProtection(pwd)); |
| 1102 | PrivateKey privateKey = pkEntry.getPrivateKey(); |
| 1103 | PublicKey publicKey = pkEntry.getCertificate().getPublicKey(); |
| 1104 | return new KeyPair(publicKey, privateKey); |
| 1105 | } catch (/* javax.crypto.BadPaddingException */IOException bpe) { |
| 1106 | log.error("Passphrase could not decrypt key: " + bpe.getMessage()); |
| 1107 | } catch (Throwable e) { |
| 1108 | log.error("Unexpected error while reading key: " + e.getMessage(), |
| 1109 | e); |
| 1110 | } finally { |
| 1111 | if (input != null) { |
| 1112 | try { |
| 1113 | input.close(); |
| 1114 | } catch (IOException e) { |
| 1115 | // ignore while closing |
| 1116 | log.trace("Error while closing: " + e.getMessage(), e); |
| 1117 | } |
| 1118 | } |
| 1119 | } |
| 1120 | return null; |
| 1121 | } |
| 1122 | |
| 1123 | public static final void writeKeyPairToFile(KeyPair keyPair, |
| 1124 | X509Certificate cert, String alias, File file, char[] pwd) { |
no test coverage detected