生成随机证书 [英] Generate random certificates

查看:147
本文介绍了生成随机证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个可以为测试目的生成随机证书字符串的实用程序类。有没有想过是否已经实现了?

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆