本文整理汇总了Java中org.bouncycastle.openssl.jcajce.JcaPEMWriter.flush方法的典型用法代码示例。如果您正苦于以下问题:Java JcaPEMWriter.flush方法的具体用法?Java JcaPEMWriter.flush怎么用?Java JcaPEMWriter.flush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.openssl.jcajce.JcaPEMWriter
的用法示例。
在下文中一共展示了JcaPEMWriter.flush方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
示例2: encodeObjectAsPemString
import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
/**
* Encodes the specified security object in PEM format, using the specified encryptor. If the encryptor is null,
* the object will not be encrypted in the generated String.
*
* @param object object to encrypt (certificate, private key, etc.)
* @param encryptor engine to encrypt the resulting PEM String, or null if no encryption should be used
* @return a PEM-encoded String
*/
private static String encodeObjectAsPemString(Object object, PEMEncryptor encryptor) {
StringWriter stringWriter = new StringWriter();
try {
JcaPEMWriter pemWriter = new JcaPEMWriter(stringWriter);
pemWriter.writeObject(object, encryptor);
pemWriter.flush();
} catch (IOException e) {
throw new ExportException("Unable to generate PEM string representing object", e);
}
return stringWriter.toString();
}
示例3: 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();
}
示例4: writePublicKey
import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
public static String writePublicKey(PublicKey pk) throws Exception {
StringWriter stringWriter = new StringWriter();
JcaPEMWriter w = new JcaPEMWriter(stringWriter);
w.writeObject(pk);
w.flush();
IOUtils.closeQuietly(w);
return stringWriter.toString();
}
示例5: write
import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
protected void write(ZipOutputStream zos, String name, Object obj) throws IOException {
ZipEntry ze = new ZipEntry(name);
zos.putNextEntry(ze);
JcaPEMWriter writer = new JcaPEMWriter(new OutputStreamWriter(zos));
writer.writeObject(obj);
writer.flush();
zos.closeEntry();
}
示例6: 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);
}
}
示例7: 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);
}
}
示例8: exportPem
import org.bouncycastle.openssl.jcajce.JcaPEMWriter; //导入方法依赖的package包/类
@AuthenticationRequired
@RequestMapping(value = "certificates/exportPem/{id}", method = RequestMethod.POST, produces = { "application/json" })
@ResponseStatus(value = HttpStatus.OK)
@ResponseBody
public RequestStatus exportPem(HttpServletRequest request,
HttpServletResponse response, @PathVariable Long id,
@RequestParam(value = "passphrase") String passphrase)
throws AccessDeniedException, UnauthorizedException,
SessionTimeoutException {
setupAuthenticatedContext(sessionUtils.getSession(request),
sessionUtils.getLocale(request));
try {
CertificateStatus status = new CertificateStatus();
status.setSuccess(false);
try {
CertificateResource resource = resourceService
.getResourceById(id);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(
new BufferedOutputStream(out));
zip.putNextEntry(new ZipEntry("certificate.pem"));
zip.write(resource.getCertificate().getBytes("UTF-8"));
zip.closeEntry();
if (StringUtils.isNotEmpty(resource.getBundle())) {
zip.putNextEntry(new ZipEntry("ca-bundle.pem"));
zip.write(resource.getBundle().getBytes("UTF-8"));
zip.closeEntry();
}
zip.putNextEntry(new ZipEntry("key.pem"));
if (passphrase == null || passphrase.trim().equals("")) {
zip.write(resource.getPrivateKey().getBytes("UTF-8"));
} else {
KeyPair keypair = X509CertificateUtils.loadKeyPairFromPEM(
new ByteArrayInputStream(resource.getPrivateKey()
.getBytes("UTF-8")), passphrase
.toCharArray());
ByteArrayOutputStream bout = new ByteArrayOutputStream();
JcaPEMWriter pem = new JcaPEMWriter(
new OutputStreamWriter(bout));
pem.writeObject(
keypair,
new JcePEMEncryptorBuilder("AES-128-CBC")
.setProvider("BC").build(
passphrase.toCharArray()));
pem.flush();
zip.write(bout.toByteArray());
pem.close();
bout.close();
}
zip.closeEntry();
zip.close();
request.getSession().setAttribute("pem", out.toByteArray());
return new RequestStatus(true);
} catch (Exception e) {
return new RequestStatus(false, e.getMessage());
}
} finally {
clearAuthenticatedContext();
}
}