生成随机证书 [英] Generate random certificates
问题描述
我正在寻找一个可以为测试目的生成随机证书字符串的实用程序类。有没有想过是否已经实现了?
I am looking for a utility class that can generate random certificate strings for testing purposes. Any idea if there is one already implemented?
推荐答案
内置的Java X500库更适合使用证书而不是生成和解析证书。您可能会找到一种方法来执行您想要的操作,但它几乎肯定会在受保护的API中出现问题( sun.security。*
)。
The built-in Java X500 libraries are geared more towards using certificates than generating and parsing certificates. You might find a way to do what you want, but it would almost certainly be messy and in a protected API (sun.security.*
).
我建议你加入Bouncy Castle库(Apache License)。它有一个名为 X509V3CertificateGenerator
的类,您可以使用它来设置证书的字段(发行者,主题,到期日期等)。
I suggest you include the Bouncy Castle library (Apache License). It has a class called X509V3CertificateGenerator
that you can use to set the fields of a certificate (issuer, subject, expiry date, etc).
然后你应该能够使用 PEMWriter
类从中获取PEM字符串。
You should then be able to get the PEM string from it using the PEMWriter
class.
这篇关于生成随机证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!