示例#1
0
  /**
   * Erases the specified id from the keystore.
   *
   * @param id The ID of the key or certificate to be deleted.
   * @throws KeyStoreException When the wrong keystore password has been provided.
   * @throws IOException For errors related to processing the keystore.
   */
  public void erase(ID id) throws KeyStoreException, IOException {
    String alias = id.toString();

    synchronized (keystore_manager) {
      KeyStore store = keystore_manager.loadKeyStore(keystore_password);

      store.deleteEntry(alias);

      keystore_manager.saveKeyStore(store, keystore_password);
    }
  }
示例#2
0
  /**
   * Adds a trusted certificate with the specified id to the key store. The certificate replaces any
   * existing certificate or private key stored at this ID.
   *
   * @param id The ID under which the certificate will be stored.
   * @param cert Certificate for the specified ID.
   * @throws KeyStoreException When the wrong keystore has been provided.
   * @throws IOException For errors related to processing the keystore.
   */
  public void setTrustedCertificate(ID id, X509Certificate cert)
      throws KeyStoreException, IOException {
    String alias = id.toString();

    synchronized (keystore_manager) {
      KeyStore store = keystore_manager.loadKeyStore(keystore_password);

      store.deleteEntry(alias);

      store.setCertificateEntry(alias, cert);

      keystore_manager.saveKeyStore(store, keystore_password);
    }
  }
示例#3
0
  /**
   * Adds a private key to the PSE using the specified ID. The key replaces any existing certificate
   * or private key stored at this ID. The key is stored using the provided key passphrase.
   *
   * @param id The ID under which the certificate chain and private key will be stored.
   * @param certchain The certificate chain matching the private key.
   * @param key The private key to be stored in the kestore.
   * @param key_password The passphrase associated with the private key or {@code null} if the key
   *     has no passphrase.
   * @throws KeyStoreException When the wrong keystore key has been provided.
   * @throws IOException For errors related to processing the keystore.
   */
  public void setKey(ID id, Certificate[] certchain, PrivateKey key, char[] key_password)
      throws KeyStoreException, IOException {

    String alias = id.toString();

    synchronized (keystore_manager) {
      KeyStore store = keystore_manager.loadKeyStore(keystore_password);

      // Remove any existing entry.
      if (store.isKeyEntry(alias)) store.deleteEntry(alias);

      store.setKeyEntry(alias, key, key_password, certchain);

      keystore_manager.saveKeyStore(store, keystore_password);
    }
  }