本文整理汇总了Java中org.bouncycastle.util.io.pem.PemWriter.flush方法的典型用法代码示例。如果您正苦于以下问题:Java PemWriter.flush方法的具体用法?Java PemWriter.flush怎么用?Java PemWriter.flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.util.io.pem.PemWriter
的用法示例。
在下文中一共展示了PemWriter.flush方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
}
示例2: 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);
}
}
示例3: 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);
}
}
示例4: 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();
}
示例5: 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 "";
}
}
示例6: 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();
}