I need to create a self signed X509 Certificate with Bouncy Castle in Java, but every class I try to include is deprecated. How can I solve this? Is there some other class to include? Thanks
相关问题
- 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
Using Bouncycastle latest version - 1.55
Update to the answer by @Bewusstsein. The bouncycastle classes are deprecated in the latest version as of this answer (5/11/2017). If you are using the latest version (1.55) or relatively latest version:
BEWARE: This answer uses an old version of the library with 11 CVEs.
Here's what i'm using (with BouncyCastle v1.38):
For
certGen.generate(keyPair.getPrivate(), "BC");
to work, BouncyCastle has to be added as a Security Provider.I confirmed that it works with this maven dependency:
This is the code used from BouncyCastle it self to generate X.509 Certificates. You will need this and this library from BC to use it. For further details on how to use it, maybe take a look at this question (Main class).
EDIT: I can't remember from which BC test I took it exactly, but here is something similar https://github.com/bcgit/bc-java/blob/master/prov/src/test/java/org/bouncycastle/pqc/jcajce/provider/test/KeyStoreTest.java
Here's a complete self-signed ECDSA certificate generator that creates certificates usable in TLS connections on both client and server side. It was tested with BouncyCastle 1.57. Similar code can be used to create RSA certificates.