/** * Loads the keystore using the given <code>KeyStore.LoadStoreParameter</code>. * * <p>Note that if this KeyStore has already been loaded, it is reinitialized and loaded again * from the given parameter. * * @param param the <code>KeyStore.LoadStoreParameter</code> that specifies how to load the * keystore, which may be <code>null</code> * @exception IllegalArgumentException if the given <code>KeyStore.LoadStoreParameter</code> input * is not recognized * @exception IOException if there is an I/O or format problem with the keystore data. If the * error is due to an incorrect <code>ProtectionParameter</code> (e.g. wrong password) the * {@link Throwable#getCause cause} of the <code>IOException</code> should be an <code> * UnrecoverableKeyException</code> * @exception NoSuchAlgorithmException if the algorithm used to check the integrity of the * keystore cannot be found * @exception CertificateException if any of the certificates in the keystore could not be loaded * @since 1.5 */ public void engineLoad(KeyStore.LoadStoreParameter param) throws IOException, NoSuchAlgorithmException, CertificateException { if (param == null) { engineLoad((InputStream) null, (char[]) null); return; } if (param instanceof KeyStore.SimpleLoadStoreParameter) { ProtectionParameter protection = param.getProtectionParameter(); char[] password; if (protection instanceof PasswordProtection) { password = ((PasswordProtection) protection).getPassword(); } else if (protection instanceof CallbackHandlerProtection) { CallbackHandler handler = ((CallbackHandlerProtection) protection).getCallbackHandler(); PasswordCallback callback = new PasswordCallback("Password: "******"Could not obtain password", e); } password = callback.getPassword(); callback.clearPassword(); if (password == null) { throw new NoSuchAlgorithmException("No password provided"); } } else { throw new NoSuchAlgorithmException( "ProtectionParameter must" + " be PasswordProtection or CallbackHandlerProtection"); } engineLoad(null, password); return; } throw new UnsupportedOperationException(); }
/** * Loads the keystore from the specified input stream and it uses the specified password to check * for integrity if supplied. * * @param stream the input stream to load the keystore from * @param password the password to check the keystore integrity with * @throws IOException if an I/O error occurs. * @throws NoSuchAlgorithmException the data integrity algorithm used cannot be found. * @throws CertificateException if any certificates could not be stored in the output stream. */ public final void load(InputStream stream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateException { keyStoreSpi.engineLoad(stream, password); }