• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java JcePEMEncryptorBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TypeDesc类代码示例发布时间:2022-05-23
下一篇:
Java JsonException类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap