I am looking for a utility class that can generate random certificate strings for testing purposes. Any idea if there is one already implemented?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
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.*
).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).You should then be able to get the PEM string from it using the
PEMWriter
class.To add to solution given by martijno,
Instead of writing your own content signer, JCAContentSigner can be used to avoid mappings to AlgorithmIdentifier (i.e. OID).
JcaContentSignerBuilder takes algorithm names as defined here.