Java Key Create getKeyStore(String filename, char[] password)

Here you can find the source of getKeyStore(String filename, char[] password)

Description

get Key Store

License

Open Source License

Declaration

public static KeyStore getKeyStore(String filename, char[] password) throws GeneralSecurityException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011 TXT e-solutions SpA
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * This work was performed within the IoT_at_Work Project
 * and partially funded by the European Commission's
 * 7th Framework Programme under the research area ICT-2009.1.3
 * Internet of Things and enterprise environments.
 *
 *
 * Authors://from  w ww.j  a  v a2  s .  co  m
 *     Cristoforo Seccia (TXT e-solutions SpA)
 *
 * Contributors:
 *      Domenico Rotondi (TXT e-solutions SpA)
 *******************************************************************************/

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.GeneralSecurityException;

import java.security.KeyStore;

import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;

public class Main {
    public static KeyStore getKeyStore(String filename, char[] password) throws GeneralSecurityException {
        try {
            KeyStore result = KeyStore.getInstance(KeyStore.getDefaultType());
            FileInputStream in = new FileInputStream(filename);
            result.load(in, password);
            in.close();
            return result;
        } catch (IOException ex) {
            throw new GeneralSecurityException(ex.getMessage(), ex);
        } catch (NoSuchAlgorithmException ex) {
            throw new GeneralSecurityException(ex.getMessage(), ex);
        } catch (CertificateException ex) {
            throw new GeneralSecurityException(ex.getMessage(), ex);
        }
    }

    public static KeyStore getKeyStore(InputStream in, char[] password) throws GeneralSecurityException {
        try {
            KeyStore result = KeyStore.getInstance(KeyStore.getDefaultType());
            result.load(in, password);
            return result;
        } catch (IOException ex) {
            throw new GeneralSecurityException(ex.getMessage(), ex);
        } catch (NoSuchAlgorithmException ex) {
            throw new GeneralSecurityException(ex.getMessage(), ex);
        } catch (CertificateException ex) {
            throw new GeneralSecurityException(ex.getMessage(), ex);
        }
    }
}

Related

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