MCPcopy Create free account
hub / github.com/TrsstProject/trsst / readKeyPairFromFile

Method readKeyPairFromFile

src/main/java/com/trsst/Command.java:1091–1121  ·  view source on GitHub ↗
(String alias, File file,
            char[] pwd)

Source from the content-addressed store, hash-verified

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) {

Callers 2

readSigningKeyPairMethod · 0.95
readEncryptionKeyPairMethod · 0.95

Calls 2

getInstanceMethod · 0.80
getEntryMethod · 0.45

Tested by

no test coverage detected