Java 8 KeyStore - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 KeyStore class.

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
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: load, setCertificateEntry, setKeyEntry, store
        signingCert = CertificateCreator.createTypicalMasterCert(caKeypair);
 
        log.fine("Done generating signing cert");
        log.fine(String.valueOf(signingCert));
 
        _ks.load(null, _keystorepass);
 
        _ks.setCertificateEntry(_caCertAlias, signingCert);
        _ks.setKeyEntry(_caPrivKeyAlias, caPrivKey, _keypassword, new Certificate[] {signingCert});
 
        File caKsFile = new File(root, _caPrivateKeystore);
 
        OutputStream os = new FileOutputStream(caKsFile);
        _ks.store(os, _keystorepass);
 
        log.fine("Wrote JKS keystore to: " +
            caKsFile.getAbsolutePath());
 
        // also export a .cer that can be imported as a trusted root 
        // to disable all warning dialogs for interception 
Full Snippet Info
7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
This code example shows how to use the following methods: getCertificate, getCertificateAlias, getCertificateChain, setCertificateEntry
 
        if (keyAlias != null)
        { 
            try 
            { 
                validate(keyStore, keyStore.getCertificate(keyAlias));
            } 
            catch (KeyStoreException kse)
            { 
                LOG.debug(kse);
                throw new CertificateException("Unable to validate certificate" +
                        " for alias [" + keyAlias + "]: " + kse.getMessage(), kse);
            } 
            result = keyAlias;            
        } 
         
        return result;
    } 
     
    /** 

7
CodeRank
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE
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
Stop searching for code, let great code find you!  Add Codota to your java IDE

Related Java 8 KeyStore Questions & Answers:

See Code Examples for Java 8 KeyStore Methods: