Java Code Examples for java.security.KeyStore#LoadStoreParameter

The following examples show how to use java.security.KeyStore#LoadStoreParameter . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyStoreSpi.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Loads the keystore using the given
 * {@code KeyStore.LoadStoreParameter}.
 *
 * <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}
 *          that specifies how to load the keystore,
 *          which may be {@code null}
 *
 * @exception IllegalArgumentException if the given
 *          {@code KeyStore.LoadStoreParameter}
 *          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} (e.g. wrong password)
 *         the {@link Throwable#getCause cause} of the
 *         {@code IOException} should be an
 *         {@code UnrecoverableKeyException}
 * @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: ", false);
            try {
                handler.handle(new Callback[] {callback});
            } catch (UnsupportedCallbackException e) {
                throw new NoSuchAlgorithmException
                    ("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();
}
 
Example 2
Source File: KeyStoreSpi.java    From j2objc with Apache License 2.0 2 votes vote down vote up
/**
 * Stores this keystore using the given
 * {@code KeyStore.LoadStoreParmeter}.
 *
 * @param param the {@code KeyStore.LoadStoreParmeter}
 *          that specifies how to store the keystore,
 *          which may be {@code null}
 *
 * @exception IllegalArgumentException if the given
 *          {@code KeyStore.LoadStoreParmeter}
 *          input is not recognized
 * @exception IOException if there was an I/O problem with data
 * @exception NoSuchAlgorithmException if the appropriate data integrity
 *          algorithm could not be found
 * @exception CertificateException if any of the certificates included in
 *          the keystore data could not be stored
 *
 * @since 1.5
 */
public void engineStore(KeyStore.LoadStoreParameter param)
            throws IOException, NoSuchAlgorithmException,
            CertificateException {
    throw new UnsupportedOperationException();
}