public static RSAPrivateKey loadFromKeyStore(URL keystoreUrl,String password) throws IOException, NoSuchAlgorithmException, CertificateException, KeyStoreException, UnrecoverableKeyException {
  logger.debug("loadFromKeyStore: keystoreUrl={}",keystoreUrl);
  URLConnection connection=keystoreUrl.openConnection();
  InputStream is=connection.getInputStream();
  try {
    if (logger.isDebugEnabled())     logger.debug("getproviders={}",Arrays.toString(Security.getProviders()));
    KeyStore keyStore;
    try {
      try {
        keyStore=KeyStore.getInstance("PKCS12","SunJSSE");
      }
 catch (      NoSuchProviderException e) {
        keyStore=KeyStore.getInstance("PKCS12",CryptoUtil.getSecurityProviderName(KeyStore.class));
      }
    }
 catch (    NoSuchProviderException e) {
      keyStore=KeyStore.getInstance("PKCS12");
    }
    logger.debug("loadFromKeyStore: keyStore Provider={}",keyStore.getProvider());
    keyStore.load(is,password == null ? null : password.toCharArray());
    Enumeration<String> aliases=keyStore.aliases();
    Key key=null;
    while (aliases.hasMoreElements()) {
      String a=(String)aliases.nextElement();
      key=keyStore.getKey(a,password == null ? null : password.toCharArray());
    }
    return (RSAPrivateKey)key;
  }
  finally {
    is.close();
  }
}

public static RSAPrivateKey loadFromKeyStore ( URL keystoreUrl , String password ) throws IOException , NoSuchAlgorithmException , CertificateException , KeyStoreException , UnrecoverableKeyException { logger . debug ( "loadFromKeyStore: keystoreUrl={}" , keystoreUrl ) ; URLConnection connection = keystoreUrl . openConnection ( ) ; InputStream is = connection . getInputStream ( ) ; try { if ( logger . isDebugEnabled ( ) ) logger . debug ( "getproviders={}" , Arrays . toString ( Security . getProviders ( ) ) ) ; KeyStore keyStore ; try { try { keyStore = KeyStore . getInstance ( "PKCS12" , "SunJSSE" ) ; } catch ( NoSuchProviderException e ) { keyStore = KeyStore . getInstance ( "PKCS12" , CryptoUtil . getSecurityProviderName ( KeyStore . class ) ) ; } } catch ( NoSuchProviderException e ) { keyStore = KeyStore . getInstance ( "PKCS12" ) ; } logger . debug ( "loadFromKeyStore: keyStore Provider={}" , keyStore . getProvider ( ) ) ; keyStore . load ( is , password == null ? null : password . toCharArray ( ) ) ; Enumeration < String > aliases = keyStore . aliases ( ) ; Key key = null ; while ( aliases . hasMoreElements ( ) ) { String a = ( String ) aliases . nextElement ( ) ; key = keyStore . getKey ( a , password == null ? null : password . toCharArray ( ) ) ; } return ( RSAPrivateKey ) key ; } finally { is . close ( ) ; } }
load private key from a key store
