Java Key Create getKeyStore(InputStream ksStream, char[] storePass)

Here you can find the source of getKeyStore(InputStream ksStream, char[] storePass)

Description

Get the Key Store Note: This method wants the InputStream to be not null.

License

Open Source License

Parameter

Parameter Description
ksStream a parameter
storePass a parameter

Exception

Parameter Description
GeneralSecurityException an exception
IOException an exception
IllegalArgumentException if ksStream is null

Declaration

public static KeyStore getKeyStore(InputStream ksStream, char[] storePass)
        throws GeneralSecurityException, IOException 

Method Source Code


//package com.java2s;
/*//www  . j a  v  a  2s.c  o  m
 * JBoss, Home of Professional Open Source.
 * Copyright 2008, Red Hat Middleware LLC, and individual contributors
 * as indicated by the @author tags. See the copyright.txt file in the
 * distribution for a full listing of individual contributors. 
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

import java.io.File;
import java.io.FileInputStream;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.security.GeneralSecurityException;

import java.security.KeyStore;

public class Main {
    /**
     * Get the Keystore given the url to the keystore file as a string
     * @param fileURL
     * @param storePass 
     * @return
     * @throws GeneralSecurityException
     * @throws IOException
     */
    public static KeyStore getKeyStore(String fileURL, char[] storePass)
            throws GeneralSecurityException, IOException {
        if (fileURL == null)
            throw new IllegalArgumentException("fileURL is null");

        File file = new File(fileURL);
        FileInputStream fis = new FileInputStream(file);
        return getKeyStore(fis, storePass);
    }

    /**
     * Get the Keystore given the URL to the keystore
     * @param url
     * @param storePass
     * @return
     * @throws GeneralSecurityException
     * @throws IOException
     */
    public static KeyStore getKeyStore(URL url, char[] storePass) throws GeneralSecurityException, IOException {
        if (url == null)
            throw new IllegalArgumentException("url is null");

        return getKeyStore(url.openStream(), storePass);
    }

    /**
     * Get the Key Store
     * <b>Note:</b> This method wants the InputStream to be not null. 
     * @param ksStream
     * @param storePass
     * @return
     * @throws GeneralSecurityException
     * @throws IOException
     * @throws IllegalArgumentException if ksStream is null
     */
    public static KeyStore getKeyStore(InputStream ksStream, char[] storePass)
            throws GeneralSecurityException, IOException {
        if (ksStream == null)
            throw new IllegalArgumentException("InputStream for the KeyStore is null");
        KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
        ks.load(ksStream, storePass);
        return ks;
    }
}

Related

  1. getKeyStore(char[] password)
  2. getKeyStore(File file, char[] storePass)
  3. getKeyStore(File keystore)
  4. getKeyStore(File keyStore)
  5. getKeyStore(final URL url, final String password)
  6. getKeyStore(String file_name, char[] storepass)
  7. getKeyStore(String filename, char[] password)
  8. getKeyStore(String filename, String password)
  9. getKeyStore(String keyStoreName, String password)