Java Key Create getKeyStore(String filename, String password)

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

Description

Get a KeyStore object given the keystore filename and password.

License

Open Source License

Declaration

public static KeyStore getKeyStore(String filename, String password) throws KeyStoreException 

Method Source Code


//package com.java2s;
import java.io.*;
import java.security.*;

public class Main {
    /**//from ww w.  ja va 2s.c o  m
    Get a KeyStore object given the keystore filename and password.
    */
    public static KeyStore getKeyStore(String filename, String password) throws KeyStoreException {
        KeyStore result = KeyStore.getInstance(KeyStore.getDefaultType());

        try {
            FileInputStream in = new FileInputStream(filename);
            result.load(in, password.toCharArray());
            in.close();
        } catch (Exception ex) {
            System.out.println("Failed to read keystore:");
            ex.printStackTrace();
        }

        return result;
    }

    /**
    Get a KeyStore object given the keystore filename and password.
    */
    public static KeyStore getKeyStore(InputStream in, String password) throws KeyStoreException {
        KeyStore result = KeyStore.getInstance(KeyStore.getDefaultType());

        try {
            result.load(in, password.toCharArray());
        } catch (Exception ex) {
            System.out.println("Failed to read keystore:");
            ex.printStackTrace();
        }

        return result;
    }
}

Related

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