Java examples for Security:Key
get KeyStore from file and password
//package com.java2s; import java.io.FileInputStream; import java.io.IOException; import java.security.KeyStore; public class Main { public static void main(String[] argv) throws Exception { String keyStorePath = "java2s.com"; String passwd = "java2s.com"; System.out.println(getKeyStore(keyStorePath, passwd)); }/* w w w .j av a2s . c o m*/ public static final String KEY_STORE = "JKS"; private static KeyStore getKeyStore(String keyStorePath, String passwd) { FileInputStream fis = null; try { fis = new FileInputStream(keyStorePath); KeyStore ks = KeyStore.getInstance(KEY_STORE); ks.load(fis, passwd.toCharArray()); return ks; } catch (Exception e) { e.printStackTrace(); } finally { try { if (fis != null) { fis.close(); } } catch (IOException e) { e.printStackTrace(); } } return null; } }