为 Bouncy Castle 加密创建证书

发布于 2024-08-29 19:29:44 字数 675 浏览 5 评论 0原文

我正在尝试创建一个自签名证书,用于使用 bouncycaste 加密电子邮件。

生成证书的最佳方式是什么?

我尝试过使用 openssl 但我遇到了证书问题。

这是我用来加密的代码,我使用的是 3des。

SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
gen.addKeyTransRecipient(x509Cert); // adds an X509Certificate

MimeBodyPart encData = 
    gen.generate(mimeBodyPart, SMIMEEnvelopedGenerator.DES_EDE3_CBC, "BC");

编辑: 抱歉,我的说法很浮夸,但我收到的错误消息似乎不太有用。

消息如下:

org.openas2.WrappedException: org.bouncycastle.mail.smime.SMIMEException:
 key invalid in message.

当我调用 SMIMEEnvelopedGenerator.generate 方法时抛出此错误。

我目前正在 Eclipse 中附加源代码,看看是否可以通过逐步执行代码来获得更有用的错误消息。

I am trying to create a self-signed certificate to use for encrypting an email using bouncycaste.

What would be the best way to generate a certificate?

I have tried using openssl but I have had problems with certificate.

Here is the code I am using to encrypt, I am using 3des.

SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
gen.addKeyTransRecipient(x509Cert); // adds an X509Certificate

MimeBodyPart encData = 
    gen.generate(mimeBodyPart, SMIMEEnvelopedGenerator.DES_EDE3_CBC, "BC");

EDIT:
Sorry for being vauge but the error message I am getting doesn't seem to be very useful.

The message is as follows:

org.openas2.WrappedException: org.bouncycastle.mail.smime.SMIMEException:
 key invalid in message.

This is thrown when I call the SMIMEEnvelopedGenerator.generate method.

I am currently attaching the source code in Eclipse to see if I can get a more useful error message by stepping through the code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

清风不识月 2024-09-05 19:29:44

我会使用 keytool 或 openssl 生成自签名证书。如果您遇到问题,请发布它们,不要只是说您遇到问题。如果您想从 Java 代码生成证书,请使用 org.bouncycastle.x509.X509V3CertificateGenerator

I would use keytool or openssl to generate a self-signed certificate. If you are having problems then post them, don't just say you are having problems. If you want to generate the certificate from your java code use the org.bouncycastle.x509.X509V3CertificateGenerator class

掩饰不了的爱 2024-09-05 19:29:44

你应该对 openssl 没问题;这是我用来生成自签名证书的命令:

openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem

这将创建一个名为 mycert.pem 的文件,其中包含两者都
私钥和自签名证书。请注意,在此示例中
密钥未加密,这对于测试目的来说是可以的。
密钥和证书均经过 PEM 编码并包含标准标头
和页脚线。

You should be okay with openssl; this is the command I would use to generate a self-signed cert:

openssl req -x509 -nodes -days 365 -newkey rsa:1024 -keyout mycert.pem -out mycert.pem

This will create a file called mycert.pem which contains both the
private key and the self signed cert. Note in this example the
key is unencrypted which is okay for testing purposes.
Both key and cert are PEM encoded and include the standard header
and footer lines.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文