本文整理汇总了Java中org.bouncycastle.openssl.jcajce.JcePEMEncryptorBuilder类的典型用法代码示例。如果您正苦于以下问题:Java JcePEMEncryptorBuilder类的具体用法?Java JcePEMEncryptorBuilder怎么用?Java JcePEMEncryptorBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JcePEMEncryptorBuilder类属于org.bouncycastle.openssl.jcajce包,在下文中一共展示了JcePEMEncryptorBuilder类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: serializePrivateKey
import org.bouncycastle.openssl.jcajce.JcePEMEncryptorBuilder; //导入依赖的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();
}
开发者ID:joyent,项目名称:java-http-signature,代码行数:19,代码来源:KeyPairLoaderTest.java
示例2: writeObject
import org.bouncycastle.openssl.jcajce.JcePEMEncryptorBuilder; //导入依赖的package包/类
/**
* @deprecated use writeObject(obj, PEMEncryptor)
*/
public void writeObject(
Object obj,
String algorithm,
char[] password,
SecureRandom random)
throws IOException
{
this.writeObject(obj, new JcePEMEncryptorBuilder(algorithm).setSecureRandom(random).setProvider(provider).build(password));
}
开发者ID:Appdome,项目名称:ipack,代码行数:13,代码来源:PEMWriter.java
示例3: encodePrivateKeyAsPem
import org.bouncycastle.openssl.jcajce.JcePEMEncryptorBuilder; //导入依赖的package包/类
@Override
public String encodePrivateKeyAsPem(PrivateKey privateKey, String passwordForPrivateKey, String encryptionAlgorithm) {
if (passwordForPrivateKey == null) {
throw new IllegalArgumentException("You must specify a password when serializing a private key");
}
PEMEncryptor encryptor = new JcePEMEncryptorBuilder(encryptionAlgorithm)
.build(passwordForPrivateKey.toCharArray());
return encodeObjectAsPemString(privateKey, encryptor);
}
开发者ID:misakuo,项目名称:Dream-Catcher,代码行数:12,代码来源:BouncyCastleSecurityProviderTool.java
示例4: exportPem
import org.bouncycastle.openssl.jcajce.JcePEMEncryptorBuilder; //导入依赖的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();
}
}
开发者ID:ludup,项目名称:hypersocket-framework,代码行数:67,代码来源:CertificateResourceController.java
注:本文中的org.bouncycastle.openssl.jcajce.JcePEMEncryptorBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论