本文整理汇总了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();
}
示例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();
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
示例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();
}
示例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 "";
}
}
示例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();
}
示例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());
}
示例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());
}
}
示例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();
}
示例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));
}