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


Java PemWriter.writeObject方法代码示例

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


在下文中一共展示了PemWriter.writeObject方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: showJcaPrivateKey

import org.bouncycastle.util.io.pem.PemWriter; //导入方法依赖的package包/类
private static void showJcaPrivateKey(PrivateKey pk) throws Exception {
    if (pk instanceof RSAPrivateKey) {
        RSAPrivateKey rsaPrivKey = (RSAPrivateKey) pk;
        PemObject rsaPem = new PemObject("RSA PRIVATE KEY", rsaPrivKey.getEncoded());
        StringWriter sw = new StringWriter();
        PemWriter pemWriter = new PemWriter(sw);
        try {
            pemWriter.writeObject(rsaPem);
        } finally {
            pemWriter.close();
        }
        System.out.println(sw.toString());
    } else if (pk instanceof java.security.interfaces.ECPrivateKey) {
        java.security.interfaces.ECPrivateKey ecPrivKey = (java.security.interfaces.ECPrivateKey) pk;
        System.out.printf("EC S: %s... (%d)\n",
                ecPrivKey.getS().toString(16).substring(0, 32),
                ecPrivKey.getS().bitLength());
        if (ecPrivKey.getParams() instanceof ECNamedCurveSpec) {
            ECNamedCurveSpec namedCurveSpec = (ECNamedCurveSpec) ecPrivKey.getParams();
            System.out.println("curve name: " + namedCurveSpec.getName());
        } else {
            System.out.println("EC params: " + ecPrivKey.getParams());
        }
    } else if (pk instanceof DSAPrivateKey) {
        DSAPrivateKey dsaPrivKey = (DSAPrivateKey) pk;
        System.out.printf("DSA X: %s... (%d)\n",
                dsaPrivKey.getX().toString(16).substring(0, 32), dsaPrivKey.getX()
                        .bitLength());
        System.out.println("DSA params: " + dsaPrivKey.getParams());
    } else {
        System.out.println("Unknown private key type: " + pk.getClass().getName());
    }
}
 
开发者ID:nelenkov,项目名称:keystore-decryptor,代码行数:34,代码来源:Main.java

示例11: serialize

import org.bouncycastle.util.io.pem.PemWriter; //导入方法依赖的package包/类
private static String serialize(String type, byte[] data) {
    PemObject obj = new PemObject(type, data);
    StringWriter out = new StringWriter();
    PemWriter writer = new PemWriter(out);
    try {
        writer.writeObject(obj);
    } catch (IOException e) {
        throw bomb(e);
    } finally {
        IOUtils.closeQuietly(writer);
    }
    return out.toString();
}
 
开发者ID:gocd,项目名称:gocd,代码行数:14,代码来源:RegistrationJSONizer.java

示例12: lengthTest

import org.bouncycastle.util.io.pem.PemWriter; //导入方法依赖的package包/类
private void lengthTest(String type, List headers, byte[] data)
    throws IOException
{
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    PemWriter pWrt = new PemWriter(new OutputStreamWriter(bOut));

    PemObject pemObj = new PemObject(type, headers, data);
    pWrt.writeObject(pemObj);

    pWrt.close();

    assertEquals(bOut.toByteArray().length, pWrt.getOutputSize(pemObj));
}
 
开发者ID:credentials,项目名称:irma_future_id,代码行数:14,代码来源:AllTests.java


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