⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e211. adding a certificate to a key store.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
// This method adds a certificate with the specified alias to the specified keystore file.
    public static void addToKeyStore(File keystoreFile, char[] keystorePassword,
             String alias, java.security.cert.Certificate cert) {
        try {
            // Create an empty keystore object
            KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    
            // Load the keystore contents
            FileInputStream in = new FileInputStream(keystoreFile);
            keystore.load(in, keystorePassword);
            in.close();
    
            // Add the certificate
            keystore.setCertificateEntry(alias, cert);
    
            // Save the new keystore contents
            FileOutputStream out = new FileOutputStream(keystoreFile);
            keystore.store(out, keystorePassword);
            out.close();
        } catch (java.security.cert.CertificateException e) {
        } catch (NoSuchAlgorithmException e) {
        } catch (FileNotFoundException e) {
            // Keystore does not exist
        } catch (KeyStoreException e) {
        } catch (IOException e) {
        }
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -