Java Key Create getKeyStore()

Here you can find the source of getKeyStore()

Description

get Key Store

License

Apache License

Declaration

static KeyStore getKeyStore() 

Method Source Code


//package com.java2s;
/*/* w  w  w  .j  a v  a  2  s.c  o m*/
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.*;

import java.security.*;

public class Main {
    private static volatile KeyStore keyStore;

    static KeyStore getKeyStore() {
        if (keyStore == null) {
            String filename = System.getProperty("keyStore");
            if (filename == null) {
                return null;
            }
            try {
                InputStream in = new BufferedInputStream(new FileInputStream(filename));
                keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
                keyStore.load(in, null);
                in.close();
            } catch (IOException e) {
                throw new RuntimeException(e.toString());
            } catch (KeyStoreException e) {
                throw new RuntimeException(e.toString());
            } catch (GeneralSecurityException e) {
                throw new RuntimeException(e.toString());
            }
        }
        return keyStore;
    }
}

Related

  1. getKeyPairGenerator(final String algorithm)
  2. getKeys()
  3. getKeySize(final Key key)
  4. getKeySize(PrivateKey key)
  5. getKeyStore()
  6. getKeyStore(byte[] bytes, char[] password)
  7. getKeyStore(Certificate[] certificateChain, PrivateKey privateKey, char[] password)
  8. getKeyStore(char[] password)
  9. getKeyStore(File file, char[] storePass)