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


Java PemWriter类代码示例

本文整理汇总了Java中org.bouncycastle.util.io.pem.PemWriter的典型用法代码示例。如果您正苦于以下问题:Java PemWriter类的具体用法?Java PemWriter怎么用?Java PemWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: createSigningRequest

import org.bouncycastle.util.io.pem.PemWriter; //导入依赖的package包/类
/**
 * Creates and returns the content of a new singing request for the specified certificate. Signing
 * requests are required by Certificate Authorities as part of their signing process. The signing request
 * contains information about the certificate issuer, subject DN, subject alternative names and public key.
 * Private keys are not included. After the Certificate Authority verified and signed the certificate a new
 * certificate is going to be returned.
 *
 * @param cert the certificate to create a signing request.
 * @param privKey the private key of the certificate.
 * @return the content of a new singing request for the specified certificate.
 */
public static String createSigningRequest(X509Certificate cert, PrivateKey privKey) throws OperatorCreationException, IOException {

    JcaPKCS10CertificationRequestBuilder csrBuilder = new JcaPKCS10CertificationRequestBuilder( //
            cert.getSubjectX500Principal(), //
            cert.getPublicKey() //
            );

    String signatureAlgorithm = "SHA256WITH" + cert.getPublicKey().getAlgorithm();

    ContentSigner signer = new JcaContentSignerBuilder(signatureAlgorithm).build(privKey);
    PKCS10CertificationRequest csr = csrBuilder.build(signer);

    StringWriter string = new StringWriter();
    PemWriter pemWriter = new PemWriter(string);

    PemObjectGenerator objGen = new MiscPEMGenerator(csr);
    pemWriter.writeObject(objGen);
    pemWriter.close();

    return string.toString();
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:33,代码来源:CertificateManager.java

示例2: generateCA

import org.bouncycastle.util.io.pem.PemWriter; //导入依赖的package包/类
protected void generateCA() throws NoSuchProviderException, NoSuchAlgorithmException, IOException, OperatorCreationException {
    KeyPair pair = generateKey();
    LocalDateTime startDate = LocalDate.now().atStartOfDay();

    X509v3CertificateBuilder builder= new X509v3CertificateBuilder(
            new X500Name("CN=ca"),
            new BigInteger("0"),
            Date.from(startDate.atZone(ZoneId.systemDefault()).toInstant()),
            Date.from(startDate.plusDays(3650).atZone(ZoneId.systemDefault()).toInstant()),
            new X500Name("CN=ca"),
            SubjectPublicKeyInfo.getInstance(pair.getPublic().getEncoded()));
    JcaContentSignerBuilder csBuilder= new JcaContentSignerBuilder("SHA512WithRSAEncryption");
    ContentSigner signer = csBuilder.build(pair.getPrivate());
    X509CertificateHolder holder = builder.build(signer);
    try (PemWriter writer = new PemWriter(new FileWriter(pemPath.toFile()))) {
        writer.writeObject(new PemObject("CERTIFICATE", holder.toASN1Structure().getEncoded()));
    }
    try (PemWriter writer = new PemWriter(new FileWriter(keyPath.toFile()))) {
        writer.writeObject(new PemObject("PRIVATE KEY", pair.getPrivate().getEncoded()));
    }
}
 
开发者ID:kawasima,项目名称:occupy-pub,代码行数:22,代码来源:CertificationAuthority.java

示例3: write

import org.bouncycastle.util.io.pem.PemWriter; //导入依赖的package包/类
public void write(String filename) throws FileNotFoundException, IOException {
	PemWriter pemWriter = new PemWriter(new OutputStreamWriter(new FileOutputStream(filename)));
	try {
		pemWriter.writeObject(this.pemObject);
	} finally {
		pemWriter.close();
	}
}
 
开发者ID:txedo,项目名称:bouncycastle-rsa-pem-write,代码行数:9,代码来源:PemFile.java

示例4: convertToPresentation

import org.bouncycastle.util.io.pem.PemWriter; //导入依赖的package包/类
@Override
public String convertToPresentation(String value, Class<? extends String> targetType, Locale locale) throws ConversionException {
    if (value == null) {
        return null;
    } else {
        try {
            final CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
            final InputStream in = new ByteArrayInputStream(Base64.decodeBase64(value));
            final Certificate certificate = certFactory.generateCertificate(in);
            final StringWriter stringWriter = new StringWriter();
            final PemWriter pemWriter = new PemWriter(stringWriter);
            final PemObject pemObject = new PemObject("CERTIFICATE", certificate.getEncoded());
            pemWriter.writeObject(pemObject);
            pemWriter.flush();
            return stringWriter.toString();
        } catch (final Exception e) {
            throw new ConversionException("Error generating X509 certificate from database byte array.", e);
        }
    }
}
 
开发者ID:bubblecloud,项目名称:ilves,代码行数:21,代码来源:CertificateConverter.java

示例5: initCertificates

import org.bouncycastle.util.io.pem.PemWriter; //导入依赖的package包/类
/**
 * Generates certificates with the tls-toolkit and then starts up the docker compose file
 */
@BeforeClass
public static void initCertificates() throws Exception {
    certificatesDirectory = Paths.get(NiFiRestConfigurationProviderSecureTest.class.getClassLoader()
            .getResource("docker-compose-NiFiRestConfigurationProviderSecureTest.yml").getFile()).getParent().toAbsolutePath().resolve("certificates-NiFiRestConfigurationProviderSecureTest");
    trustSslContext = initCertificates(certificatesDirectory, Arrays.asList("c2", "mocknifi"));
    healthCheckSocketFactory = trustSslContext.getSocketFactory();

    KeyStore mockNiFiKeyStore = KeyStore.getInstance("JKS");
    try (InputStream inputStream = Files.newInputStream(certificatesDirectory.resolve("mocknifi").resolve("keystore.jks"))) {
        mockNiFiKeyStore.load(inputStream, "badKeystorePass".toCharArray());
    }
    try (PemWriter pemWriter = new PemWriter(new OutputStreamWriter(Files.newOutputStream(certificatesDirectory.resolve("mocknifi").resolve("cert.pem"))))) {
        pemWriter.writeObject(new JcaMiscPEMGenerator(mockNiFiKeyStore.getKey(TlsToolkitStandalone.NIFI_KEY, "badKeyPass".toCharArray())));
        for (Certificate certificate : mockNiFiKeyStore.getCertificateChain(TlsToolkitStandalone.NIFI_KEY)) {
            pemWriter.writeObject(new JcaMiscPEMGenerator(certificate));
        }
    }

    KeyStore mockNiFiTrustStore = KeyStore.getInstance("JKS");
    try (InputStream inputStream = Files.newInputStream(certificatesDirectory.resolve("mocknifi").resolve("truststore.jks"))) {
        mockNiFiTrustStore.load(inputStream, "badTrustPass".toCharArray());
    }
    try (PemWriter pemWriter = new PemWriter(new OutputStreamWriter(Files.newOutputStream(certificatesDirectory.resolve("mocknifi").resolve("ca.pem"))))) {
        pemWriter.writeObject(new JcaMiscPEMGenerator(mockNiFiTrustStore.getCertificate(TlsToolkitStandalone.NIFI_CERT)));
    }

    docker.before();
}
 
开发者ID:apache,项目名称:nifi-minifi,代码行数:32,代码来源:NiFiRestConfigurationProviderSecureTest.java

示例6: writeX509Certificate

import org.bouncycastle.util.io.pem.PemWriter; //导入依赖的package包/类
private static void writeX509Certificate(X509Certificate certificate, Writer sw) {
    if (certificate == null) {
        throw new IllegalArgumentException("certificate must be defined.");
    }
    if (sw == null) {
        throw new IllegalArgumentException("sw must be defined.");
    }
    try {
        PemWriter writer = new PemWriter(sw);
        writer.writeObject(new PemObject("CERTIFICATE", certificate.getEncoded()));
        writer.flush();
    } catch (CertificateEncodingException | IOException e) {
        throw new RuntimeException("Unable to write a certificate in output stream", e);
    }
}
 
开发者ID:kodokojo,项目名称:kodokojo,代码行数:16,代码来源:SSLUtils.java

示例7: writeRsaPrivateKey

import org.bouncycastle.util.io.pem.PemWriter; //导入依赖的package包/类
public static void writeRsaPrivateKey(RSAPrivateKey privateKey, Writer sw) {
    try {
        PemWriter writer = new PemWriter(sw);
        writer.writeObject(new PemObject("RSA PRIVATE KEY", privateKey.getEncoded()));
        writer.flush();
        //outputStream.write(pkcs8EncodedKeySpec.getEncoded());

    } catch (IOException e) {
        throw new RuntimeException("Unable to write a private rsa key in output stream", e);
    }
}
 
开发者ID:kodokojo,项目名称:kodokojo,代码行数:12,代码来源:RSAUtils.java

示例8: writeX509CertificateChain

import org.bouncycastle.util.io.pem.PemWriter; //导入依赖的package包/类
public static void writeX509CertificateChain(X509Certificate[] certificates, String path) throws IOException, CertificateEncodingException {
    try (Writer writer = new FileWriter(path); PemWriter pemWriter = new PemWriter(writer)) {
        for (X509Certificate certificate : certificates) {
            pemWriter.writeObject(new PemObject("CERTIFICATE", certificate.getEncoded()));
        }
    }
}
 
开发者ID:porunov,项目名称:acme_client,代码行数:8,代码来源:IOManager.java

示例9: toPEM

import org.bouncycastle.util.io.pem.PemWriter; //导入依赖的package包/类
public static byte[] toPEM(PKCS10CertificationRequest csr) throws IOException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    PemWriter pemWriter = new PemWriter(new OutputStreamWriter(os, StandardCharsets.UTF_8));
    try {
        pemWriter.writeObject(new JcaMiscPEMGenerator(csr));
        pemWriter.flush();
    } finally {
        pemWriter.close();
    }
    return os.toByteArray();
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:12,代码来源:PEMUtils.java

示例10: writeKey

import org.bouncycastle.util.io.pem.PemWriter; //导入依赖的package包/类
/**
 * Write the given key to the given file.
 *
 * @param key
 * @param file
 */
private void writeKey(Key key, File file) throws IOException {
    file.createNewFile();

    try (PemWriter pemWriter = new PemWriter(new OutputStreamWriter(new FileOutputStream(file)))) {
        PemObject pemObject = new PemObject("Key", key.getEncoded());

        pemWriter.writeObject(pemObject);
    }
}
 
开发者ID:web-push-libs,项目名称:webpush-java,代码行数:16,代码来源:GenerateKeyHandler.java

示例11: toPEM

import org.bouncycastle.util.io.pem.PemWriter; //导入依赖的package包/类
public static String toPEM(String type, byte[] data) {
    try{
        StringWriter writer = new StringWriter();
        PemWriter pemWriter = new PemWriter(writer);
        pemWriter.writeObject(new PemObject(type, data));
        pemWriter.flush();
        pemWriter.close();
        return writer.toString();
    }catch (Exception e){
        return "";
    }

}
 
开发者ID:aykutalparslan,项目名称:Telegram-Server,代码行数:14,代码来源:Utilities.java

示例12: certificateAsPem

import org.bouncycastle.util.io.pem.PemWriter; //导入依赖的package包/类
private String certificateAsPem(X509Certificate x509) throws CertificateEncodingException, IOException {
    StringWriter sw = new StringWriter();
    PemWriter writer = new PemWriter(sw);
    PemObject pemObject = new PemObject("CERTIFICATE", x509.getEncoded());
    try {
        writer.writeObject(pemObject);
        writer.flush();
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        writer.close();
    }
    return sw.toString();
}
 
开发者ID:apiman,项目名称:apiman-plugins,代码行数:15,代码来源:KeycloakOauthPolicyTest.java

示例13: convertToPEM

import org.bouncycastle.util.io.pem.PemWriter; //导入依赖的package包/类
private static String convertToPEM(Object obj) throws DSSException {
	try (StringWriter out = new StringWriter(); PemWriter pemWriter = new PemWriter(out)) {
		pemWriter.writeObject(new JcaMiscPEMGenerator(obj));
		pemWriter.flush();
		return out.toString();
	} catch (Exception e) {
		throw new DSSException("Unable to convert DER to PEM", e);
	}
}
 
开发者ID:esig,项目名称:dss,代码行数:10,代码来源:DSSUtils.java

示例14: write

import org.bouncycastle.util.io.pem.PemWriter; //导入依赖的package包/类
/**
 * Writes the signed certificate request to a {@link Writer}.
 *
 * @param w
 *            {@link Writer} to write the PEM file to. The {@link Writer} is closed
 *            after use.
 */
public void write(Writer w) throws IOException {
    if (csr == null) {
        throw new IllegalStateException("sign CSR first");
    }

    try (PemWriter pw = new PemWriter(w)) {
        pw.writeObject(new PemObject("CERTIFICATE REQUEST", getEncoded()));
    }
}
 
开发者ID:shred,项目名称:acme4j,代码行数:17,代码来源:CSRBuilder.java

示例15: showCert

import org.bouncycastle.util.io.pem.PemWriter; //导入依赖的package包/类
private static void showCert(KeystoreBlob ksBlob) throws Exception {
    X509Certificate cert = ksBlob.getCertificate();
    PemObject certPem = new PemObject("CERTIFICATE", cert.getEncoded());
    StringWriter sw = new StringWriter();
    PemWriter pemWriter = new PemWriter(sw);
    try {
        pemWriter.writeObject(certPem);
    } finally {
        pemWriter.close();
    }
    System.out.println(sw.toString());
}
 
开发者ID:nelenkov,项目名称:keystore-decryptor,代码行数:13,代码来源:Main.java


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