当前位置: 首页>>代码示例>>Java>>正文


Java JcaPEMWriter.close方法代码示例

本文整理汇总了Java中org.bouncycastle.openssl.jcajce.JcaPEMWriter.close方法的典型用法代码示例。如果您正苦于以下问题:Java JcaPEMWriter.close方法的具体用法?Java JcaPEMWriter.close怎么用?Java JcaPEMWriter.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.openssl.jcajce.JcaPEMWriter的用法示例。


在下文中一共展示了JcaPEMWriter.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPEMStringFromRSAKeyPair

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
/**
 * Converts RSA private key to PEM string.
 *
 * @param rsaKeyPair
 * @return PEM string
 */
public static String getPEMStringFromRSAKeyPair(final RSAKeyPair rsaKeyPair) {
    final StringWriter pemStrWriter = new StringWriter();
    final JcaPEMWriter pemWriter = new JcaPEMWriter(pemStrWriter);
    try {
        final KeyPair keyPair = new KeyPair(rsaKeyPair.getPublic(), rsaKeyPair.getPrivate());
        pemWriter.writeObject(keyPair.getPrivate());
        pemWriter.close();

    } catch (final IOException e) {
        logger.warn("Caught exception:" + e.getMessage());
        return "";
    }

    return pemStrWriter.toString();
}
 
开发者ID:rovemonteux,项目名称:silvertunnel-monteux,代码行数:22,代码来源:Encryption.java

示例2: serializePrivateKey

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
private byte[] serializePrivateKey(final KeyPair keyPair,
                                   final String passphrase) throws Exception {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final JcaPEMWriter jcaPEMWriter = new JcaPEMWriter(new OutputStreamWriter(baos,
            StandardCharsets.US_ASCII));

    if (passphrase != null) {
        final PEMEncryptor pemEncryptor = new JcePEMEncryptorBuilder("AES-128-CBC").build(passphrase.toCharArray());
        final JcaMiscPEMGenerator pemGenerator = new JcaMiscPEMGenerator(keyPair.getPrivate(), pemEncryptor);
        jcaPEMWriter.writeObject(pemGenerator);
    } else {
        jcaPEMWriter.writeObject(keyPair.getPrivate());
    }

    jcaPEMWriter.flush();
    jcaPEMWriter.close();
    return baos.toByteArray();
}
 
开发者ID:joyent,项目名称:java-http-signature,代码行数:19,代码来源:KeyPairLoaderTest.java

示例3: convertCertificateToPEM

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
private static String convertCertificateToPEM(X509Certificate signedCertificate) throws IOException {
    StringWriter signedCertificatePEMDataStringWriter = new StringWriter();
    JcaPEMWriter pemWriter                            = new JcaPEMWriter(signedCertificatePEMDataStringWriter);
    pemWriter.writeObject(signedCertificate);
    pemWriter.close();
    return signedCertificatePEMDataStringWriter.toString();
}
 
开发者ID:Zubnix,项目名称:rtcdcjava,代码行数:8,代码来源:RTCCertificate.java

示例4: getStringFromPublicKey

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
private static String getStringFromPublicKey(PublicKey pubKey) throws InvalidKeyPairException {
    try {
        StringWriter writer = new StringWriter();
        JcaPEMWriter pemWriter = new JcaPEMWriter(writer);
        pemWriter.writeObject(pubKey);
        pemWriter.close();
        return writer.toString();
    } catch (IOException e) {
        throw new InvalidKeyPairException("Could not encode public key. PEM encoding failed.",
                e);
    }
}
 
开发者ID:michaelnetter,项目名称:dracoon-dropzone,代码行数:13,代码来源:Crypto.java

示例5: toPEMFormat

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
public static String toPEMFormat(Key key) {
    StringWriter sw = new StringWriter();
    JcaPEMWriter pemWriter = new JcaPEMWriter(sw);
    try {
        pemWriter.writeObject(key);
        pemWriter.close();

        return sw.toString();

    } catch (IOException x) {
        throw new RuntimeException("Failed to serialize key", x);
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:14,代码来源:KeyUtil.java

示例6: toPEMformat

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
/**
 * Serialize Certificate in PEM format
 */
public static String toPEMformat(X509Certificate certificate) {
    StringWriter sw = new StringWriter();
    JcaPEMWriter pemWriter = new JcaPEMWriter(sw);
    try {
        pemWriter.writeObject(certificate);
        pemWriter.close();

        return sw.toString();

    } catch (IOException x) {
        throw new RuntimeException("Failed to serialize certificate", x);
    }
}
 
开发者ID:vmware,项目名称:photon-model,代码行数:17,代码来源:CertificateUtil.java

示例7: certificationRequestToPEM

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
/**
 * certificationRequestToPEM - Convert a PKCS10CertificationRequest to PEM
 * format.
 *
 * @param csr The Certificate to convert
 * @return An equivalent PEM format certificate.
 * @throws IOException
 */

private String certificationRequestToPEM(PKCS10CertificationRequest csr) throws IOException {
    PemObject pemCSR = new PemObject("CERTIFICATE REQUEST", csr.getEncoded());

    StringWriter str = new StringWriter();
    JcaPEMWriter pemWriter = new JcaPEMWriter(str);
    pemWriter.writeObject(pemCSR);
    pemWriter.close();
    str.close();
    return str.toString();
}
 
开发者ID:hyperledger,项目名称:fabric-sdk-java,代码行数:20,代码来源:CryptoPrimitives.java

示例8: getCertificatePEM

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
/**
 * Get the CA certificate (self signed public key)
 * @return certificate string in PEM form
 * @throws IOException 
 */
public String getCertificatePEM() throws IOException{
	StringWriter w = new StringWriter();
	JcaPEMWriter writer = new JcaPEMWriter(w);
	writer.writeObject(cacert);
	writer.close();
	return w.toString();
}
 
开发者ID:aktin,项目名称:ca,代码行数:13,代码来源:CertificateManager.java

示例9: csrToString

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
private String csrToString(PKCS10CertificationRequest csr) throws IOException{
	StringWriter w = new StringWriter();
	JcaPEMWriter p = new JcaPEMWriter(w);
	p.writeObject(csr);
	p.close();
	return w.toString();
}
 
开发者ID:aktin,项目名称:ca,代码行数:8,代码来源:CertificateManager.java

示例10: generatePkcs8

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
private InputStream generatePkcs8(PrivateKey kp) throws IOException, NoSuchAlgorithmException, InvalidKeySpecException {
    logger.debug("Generate a Pkcs8 private key: " + kp.getFormat());


    StringWriter out = new StringWriter();
    JcaPEMWriter writer = new JcaPEMWriter(out);
    writer.writeObject(kp);
    writer.close();

    return new ByteArrayInputStream(out.toString().getBytes());
}
 
开发者ID:DTStack,项目名称:jlogstash-input-plugin,代码行数:12,代码来源:PrivateKeyConverter.java

示例11: pemOf

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
public static String pemOf(Object pemObject) throws IOException {
  StringWriter sw = new StringWriter();
  JcaPEMWriter writer = new JcaPEMWriter(sw);
  writer.writeObject(pemObject);
  writer.close();
  return sw.toString();
}
 
开发者ID:cloudfoundry-incubator,项目名称:credhub,代码行数:8,代码来源:CertificateFormatter.java

示例12: exportPEMObject

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
/**
 * Helper method for exporting PEM object.
 * 
 * @param object
 *            to export in PEM format.
 * @param filename
 *            for the file to export.
 */
public void exportPEMObject(Object pemObject, String filename) throws IOException {
	Writer writer;
	writer = new FileWriter(filename);
	JcaPEMWriter jcaPemWriter = new JcaPEMWriter(writer);
	jcaPemWriter.writeObject(pemObject);
	jcaPemWriter.flush();
	jcaPemWriter.close();
}
 
开发者ID:SAMLRaider,项目名称:SAMLRaider,代码行数:17,代码来源:FileHelper.java

示例13: saveKeyPair

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
public static void saveKeyPair(KeyPair pair, OutputStream keyfile)
		throws CertificateException {

	JcaPEMWriter writer = new JcaPEMWriter(new OutputStreamWriter(keyfile));
	try {
		writer.writeObject(pair.getPrivate());
		writer.flush();
		writer.close();
	} catch (IOException e) {
		throw new CertificateException("Failed to save key pair", e);
	}
}
 
开发者ID:ludup,项目名称:hypersocket-framework,代码行数:13,代码来源:X509CertificateUtils.java

示例14: saveCertificate

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
public static void saveCertificate(Certificate[] certs,
		OutputStream certfile) throws CertificateException {
	JcaPEMWriter writer = new JcaPEMWriter(new OutputStreamWriter(certfile));

	try {
		for (Certificate c : certs) {
			writer.writeObject(c);
		}
		writer.flush();
		writer.close();
	} catch (IOException e) {
		throw new CertificateException("Failed to save certificate", e);
	}

}
 
开发者ID:ludup,项目名称:hypersocket-framework,代码行数:16,代码来源:X509CertificateUtils.java

示例15: saveCertKeyPair

import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
private void saveCertKeyPair() {
    try {
        FileOutputStream certOut = new FileOutputStream(certFile);
        FileOutputStream keyOut = new FileOutputStream(keyFile);

        // Write the certificate in OpenSSL PEM format (important for the server)
        StringWriter strWriter = new StringWriter();
        JcaPEMWriter pemWriter = new JcaPEMWriter(strWriter);
        pemWriter.writeObject(cert);
        pemWriter.close();

        // Line endings MUST be UNIX for the PC to accept the cert properly
        OutputStreamWriter certWriter = new OutputStreamWriter(certOut);
        String pemStr = strWriter.getBuffer().toString();
        for (int i = 0; i < pemStr.length(); i++) {
            char c = pemStr.charAt(i);
            if (c != '\r')
                certWriter.append(c);
        }
        certWriter.close();

        // Write the private out in PKCS8 format
        keyOut.write(key.getEncoded());

        certOut.close();
        keyOut.close();

        LimeLog.info("Saved generated key pair to disk");
    } catch (IOException e) {
        // This isn't good because it means we'll have
        // to re-pair next time
        e.printStackTrace();
    }
}
 
开发者ID:moonlight-stream,项目名称:moonlight-android,代码行数:35,代码来源:AndroidCryptoProvider.java


注:本文中的org.bouncycastle.openssl.jcajce.JcaPEMWriter.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。