Package java.security

Examples of java.security.KeyStore


    if (socketFactory == null) {
      try {
        char[] pass =  AgentServer.getProperty(PASS, "changeit").toCharArray();
        String keyFile = AgentServer.getProperty(KEYFILE, ".keystore");
        KeyStore ks = KeyStore.getInstance("JKS");
        ks.load(new FileInputStream(keyFile), pass);

        TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
        tmf.init(ks);

        SSLContext ctx = SSLContext.getInstance("TLS");
View Full Code Here


    if (serverSocketFactory == null) {
      try {
        char[] pass =  AgentServer.getProperty(PASS, "changeit").toCharArray();
        String keyFile = AgentServer.getProperty(KEYFILE, ".keystore");
        KeyStore ks = KeyStore.getInstance("JKS");
        ks.load(new FileInputStream(keyFile), pass);

        KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
        kmf.init(ks, pass);

        SSLContext ctx = SSLContext.getInstance("TLS");
View Full Code Here

    if (logger.isLoggable(BasicLevel.DEBUG))
      logger.log(BasicLevel.DEBUG,
                 "SSLTcpProxyService.createSocketFactory : keystoreFile=" + keystoreFile);
   
    KeyStore keystore = KeyStore.getInstance(ksType);
    keystore.load(new FileInputStream(keystoreFile),keyStorePass);
   
    KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
    kmf.init(keystore,keyStorePass);
   
    TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
View Full Code Here

        }

        InputStream keystoreInputStream = null;

        KeyManager[] keyManagers=null;
        KeyStore keyStore = null;
        try
        {
            if (_keystore!=null)
            {
                keystoreInputStream=Resource.newResource(_keystore).getInputStream();
                keyStore = KeyStore.getInstance(_keystoreType);
                keyStore.load(keystoreInputStream,_password==null?null:_password.toString().toCharArray());
            }
        }
        finally
        {
            if (keystoreInputStream != null)
                keystoreInputStream.close();
        }

        KeyManagerFactory keyManagerFactory=KeyManagerFactory.getInstance(_sslKeyManagerFactoryAlgorithm);
        keyManagerFactory.init(keyStore,_keyPassword==null?(_password==null?null:_password.toString().toCharArray()):_keyPassword.toString().toCharArray());
        keyManagers=keyManagerFactory.getKeyManagers();


        TrustManager[] trustManagers=null;
        InputStream truststoreInputStream = null;
        KeyStore trustStore = null;
        try
        {
            if (_truststore!=null)
            {
                truststoreInputStream = Resource.newResource(_truststore).getInputStream();
                trustStore=KeyStore.getInstance(_truststoreType);
                trustStore.load(truststoreInputStream,_trustPassword==null?null:_trustPassword.toString().toCharArray());
            }
        }
        finally
        {
            if (truststoreInputStream != null)
View Full Code Here

    name = "SSLNetwork#" + AgentServer.getServerId();

    char[] pass =  AgentServer.getProperty(PASS, "changeit").toCharArray();
    String keyFile = AgentServer.getProperty(KEYFILE, ".keystore");

    KeyStore keystore = KeyStore.getInstance(AgentServer.getProperty(KTYPE, "JKS"));
    keystore.load(new FileInputStream(keyFile), pass);

    KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
    kmf.init(keystore, pass);

    TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
View Full Code Here

    if (logger.isLoggable(BasicLevel.DEBUG))
      logger.log(BasicLevel.DEBUG,
                 "SSLTcpProxyService.createServerSocketFactory:" + keystoreFile + ':' + new String(keyStorePass));

    KeyStore keystore = KeyStore.getInstance(ksType);
    keystore.load(new FileInputStream(keystoreFile), keyStorePass);

    KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
    kmf.init(keystore,keyStorePass);

    TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
View Full Code Here

    if (!f.exists()) {
      throw new IllegalStateException("The keystore file named '" + f + "' was not found.");
    }

    // Gets the keystore instance
    KeyStore keyStore = null;
    try {
      keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
    } catch (KeyStoreException e) {
      throw new IllegalStateException("Error while getting a keystore ':" + e.getMessage());
    }

    // Load the keystore file
    try {
      keyStore.load(new BufferedInputStream(new FileInputStream(f)), keystorePass.toCharArray());
    } catch (NoSuchAlgorithmException e) {
      throw new IllegalStateException("Error while loading the keystore file '" + f + "'." + e.getMessage());
    } catch (CertificateException e) {
      throw new IllegalStateException("Error while loading the keystore file '" + f + "'." + e.getMessage());
    } catch (FileNotFoundException e) {
      throw new IllegalStateException("Error while loading the keystore file '" + f + "'." + e.getMessage());
    } catch (IOException e) {
      throw new IllegalStateException("Error while loading the keystore file '" + f + "'." + e.getMessage());
    }

    // Get certificate
    Certificate cert;
    try {
      cert = keyStore.getCertificate(alias);
    } catch (KeyStoreException e) {
      throw new IllegalStateException("Error while getting the alias '" + alias + "' in the keystore file '" + keystoreFile + "':" + e.getMessage());
    }

    // set the public key
View Full Code Here

     */
    public static SymmetricCryptor getSymmectricCryptor(URL keyResource) throws CryptoException, IOException {
    ArgCheck.isNotNull(keyResource);
    InputStream stream = keyResource.openStream();
    try {
        KeyStore store = KeyStore.getInstance("JCEKS"); //$NON-NLS-1$
        store.load(stream, DEFAULT_STORE_PASSWORD.toCharArray());
        Key key = store.getKey(DEFAULT_ALIAS, DEFAULT_STORE_PASSWORD.toCharArray());
        return new SymmetricCryptor(key);
        } catch (GeneralSecurityException e) {
            throw new CryptoException(e);
    } finally {
      stream.close();
View Full Code Here

   
    private static void saveKey(String file, SecretKey key) throws CryptoException, IOException {
      ArgCheck.isNotNull(file);
      FileOutputStream fos = new FileOutputStream(file);
      try {
          KeyStore store = KeyStore.getInstance("JCEKS"); //$NON-NLS-1$
          store.load(null,null);
        store.setKeyEntry(DEFAULT_ALIAS, key, DEFAULT_STORE_PASSWORD.toCharArray(),null);
        store.store(fos, DEFAULT_STORE_PASSWORD.toCharArray());
      } catch (GeneralSecurityException e) {
        throw new CryptoException(e);
      } finally {
        fos.close();
     
View Full Code Here

          // doesn't look very empty, bail!
       
        return;
      }
     
      KeyStore keystore = getTrustStore();
     
      if ( keystore.size() == 0 ){
       
        File cacerts = new File( new File( new File( System.getProperty( "java.home" ), "lib" ), "security" ), "cacerts" );
       
        if ( cacerts.exists()){
         
View Full Code Here

TOP

Related Classes of java.security.KeyStore

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.