KeyStore store - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for KeyStore store method.

This code example shows how to use the following methods:deleteEntry, setCertificateEntry, setKeyEntry, store
      final PrivateKey privKey)
      throws KeyStoreException, CertificateException, NoSuchAlgorithmException 
  { 
    // String alias = ThumbprintUtil.getThumbprint(cert); 
 
    _ks.deleteEntry(hostname);
 
    _ks.setCertificateEntry(hostname, cert);
    _ks.setKeyEntry(hostname, privKey, _keypassword, new Certificate[] {cert});
 
    if (persistImmediately)
    { 
      persist(); 
    } 
 
  } 
 
  /** 
   * Writes the keystore and certificate/keypair mappings to disk. 
   *  

7
CodeRank
This code example shows how to use the following methods:store
  private static void saveKeyStore(KeyStore ks, String filename,
                                   String password)
    throws GeneralSecurityException, IOException { 
    FileOutputStream out = new FileOutputStream(filename);
    try { 
      ks.store(out, password.toCharArray());
    } finally { 
      out.close();
    } 
  } 
 
  public static void createKeyStore(String filename,
                                    String password, String alias,
                                    Key privateKey, Certificate cert)
    throws GeneralSecurityException, IOException { 
    KeyStore ks = createEmptyKeyStore();
    ks.setKeyEntry(alias, privateKey, password.toCharArray(),
                   new Certificate[]{cert});
    saveKeyStore(ks, filename, password);
  } 
6
CodeRank
This code example shows how to use the following methods:load, setCertificateEntry, store
                    mKnownServersStore.load(in, LOCAL_TRUSTSTORE_PASSWORD.toCharArray());
                } finally { 
                    in.close();
                } 
            } else { 
                mKnownServersStore.load(null, LOCAL_TRUSTSTORE_PASSWORD.toCharArray()); // necessary to initialize an empty KeyStore instance
            } 
        } 
        return mKnownServersStore;
    } 
     
     
    public static void addCertToKnownServersStore(Certificate cert, Context context) throws  KeyStoreException, NoSuchAlgorithmException, 
                                                                                            CertificateException, IOException { 
        KeyStore knownServers = getKnownServersStore(context);
        knownServers.setCertificateEntry(Integer.toString(cert.hashCode()), cert);
        FileOutputStream fos = null;
        try { 
            fos = context.openFileOutput(LOCAL_TRUSTSTORE_FILENAME, Context.MODE_PRIVATE);
            knownServers.store(fos, LOCAL_TRUSTSTORE_PASSWORD.toCharArray());

7
CodeRank
This code example shows how to use the following methods:containsAlias, getKey, load, store
    } 
 
    private void checkStore(KeyStore ks, byte[] data)
        throws Exception 
    { 
        ks.load(new ByteArrayInputStream(data), oldStorePass);
 
        if (!ks.containsAlias("android"))
        { 
            fail("cannot find alias"); 
        } 
 
        Key key = ks.getKey("android", oldStorePass);
        if (key == null)
        { 
            fail("cannot find key"); 
        } 
 
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
 

7
CodeRank
This code example shows how to use the following methods:containsAlias, deleteEntry, setCertificateEntry, store
    } 
 
    private synchronized void store() { 
        try { 
            FileOutputStream fos = mContext.openFileOutput(KEYSTORE_FILENAME, Context.MODE_PRIVATE);
            mKeyStore.store(fos, KEYSTORE_PASSWORD);
            fos.close();
        } catch (IOException e) {
            throw new IllegalStateException("Unable to store keyStore", e);
        } catch (GeneralSecurityException e) {
            throw new IllegalStateException("Unable to store keyStore", e);
        } 
    } 
 
    /** 
     * Returns the name that should be used in a new certificate. 
     * <p> 
     * The format is: "CN=anymote/PRODUCT/DEVICE/MODEL/unique identifier" 
     */ 
    private static final String getCertificateName(String id) {

6
CodeRank
This code example shows how to use the following methods:containsAlias, deleteEntry, setCertificateEntry, store
    } 
 
    private synchronized void store() { 
        try { 
            FileOutputStream fos = mContext.openFileOutput(KEYSTORE_FILENAME, Context.MODE_PRIVATE);
            mKeyStore.store(fos, KEYSTORE_PASSWORD);
            fos.close();
        } catch (IOException e) {
            throw new IllegalStateException("Unable to store keyStore", e);
        } catch (GeneralSecurityException e) {
            throw new IllegalStateException("Unable to store keyStore", e);
        } 
    } 
 
    /** 
     * Returns the name that should be used in a new certificate. 
     * <p> 
     * The format is: "CN=anymote/PRODUCT/DEVICE/MODEL/unique identifier" 
     */ 
    private static final String getCertificateName(String id) {

6
CodeRank
This code example shows how to use the following methods:containsAlias, getKey, load, store
    } 
 
    private void checkStore(KeyStore ks, byte[] data)
        throws Exceptionks.load(new ByteArrayInputStream(data), oldStorePass);
 
        if (!ks.containsAlias("android"))
        { 
            fail("cannot find alias"); 
        } 
 
        Key key = ks.getKey("android", oldStorePass);
        if (key == null)
        { 
            fail("cannot find key"); 
        } 
 
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
 

6
CodeRank
This code example shows how to use the following methods:containsAlias, deleteEntry, setCertificateEntry, store
 
  private void store(KeyStore keyStore) {
    try { 
      FileOutputStream fos =
          mContext.openFileOutput(KEYSTORE_FILENAME, Context.MODE_PRIVATE);
      keyStore.store(fos, KEYSTORE_PASSWORD);
      fos.close();
    } catch (IOException e) {
      throw new IllegalStateException("Unable to store keyStore", e);
    } catch (GeneralSecurityException e) {
      throw new IllegalStateException("Unable to store keyStore", e);
    } 
  } 
 
  /** 
   * Stores current state of key store. 
   */ 
  public synchronized void store() { 
    store(mKeyStore);
  } 

6
CodeRank
This code example shows how to use the following methods:getKey, setKeyEntry, store
    public synchronized KeyPair generate() {
        try { 
            String alias = "key_" + count;
            ++count;
 
            PrivateKey key = (PrivateKey) pregeneratedKeys.getKey(alias, PASSPHRASE);
            KeyPair result;
            if (key == null) {
                result = super.generate();
                pregeneratedKeys.setKeyEntry(alias, result.getPrivate(), PASSPHRASE, new Certificate[]{createCertificate(result).getCertificate()});
                OutputStream output = new FileOutputStream(keyStoreFile);
                try { 
                    pregeneratedKeys.store(output, PASSPHRASE);
                } finally { 
                    IOUtils.closeQuietly(output);
                } 
            } else { 
                Certificate certificate = pregeneratedKeys.getCertificateChain(alias)[0];
                result = new KeyPair(certificate.getPublicKey(), key);
            } 
6
CodeRank
This code example shows how to use the following methods:containsAlias, deleteEntry, setCertificateEntry, store
 
  private void store(KeyStore keyStore) {
    try { 
      FileOutputStream fos =
          mContext.openFileOutput(KEYSTORE_FILENAME, Context.MODE_PRIVATE);
      keyStore.store(fos, KEYSTORE_PASSWORD);
      fos.close();
    } catch (IOException e) {
      throw new IllegalStateException("Unable to store keyStore", e);
    } catch (GeneralSecurityException e) {
      throw new IllegalStateException("Unable to store keyStore", e);
    } 
  } 
 
  /** 
   * Stores current state of key store. 
   */ 
  public synchronized void store() { 
    store(mKeyStore);
  } 

6
CodeRank

Related KeyStore store Questions & Answers:

store Method Overview
Stores this keystore to the given output stream, and protects its integrity with the given password.
See Code Examples for other Java 8 KeyStore Methods: