Example #1
0
 public static void createKeyStore(
     String filename, Password password, String alias, Key privateKey, Certificate cert)
     throws GeneralSecurityException, IOException {
   KeyStore ks = createEmptyKeyStore();
   ks.setKeyEntry(alias, privateKey, password.value().toCharArray(), new Certificate[] {cert});
   saveKeyStore(ks, filename, password);
 }
Example #2
0
 private static void saveKeyStore(KeyStore ks, String filename, Password password)
     throws GeneralSecurityException, IOException {
   FileOutputStream out = new FileOutputStream(filename);
   try {
     ks.store(out, password.value().toCharArray());
   } finally {
     out.close();
   }
 }
Example #3
0
 public static <T extends Certificate> void createTrustStore(
     String filename, Password password, Map<String, T> certs)
     throws GeneralSecurityException, IOException {
   KeyStore ks = KeyStore.getInstance("JKS");
   try {
     FileInputStream in = new FileInputStream(filename);
     ks.load(in, password.value().toCharArray());
     in.close();
   } catch (EOFException e) {
     ks = createEmptyKeyStore();
   }
   for (Map.Entry<String, T> cert : certs.entrySet()) {
     ks.setCertificateEntry(cert.getKey(), cert.getValue());
   }
   saveKeyStore(ks, filename, password);
 }