flightlessbird
flightlessbird

Reputation: 423

How should I convert a PublicKey to a Certificate in Java

I have a circumstance where I need to store one or more public keys for use in authentication. I would like to store them in a KeyStore as TrustedCertificates - is there a way to do this, ideally using standard java.security classes?

I have seen that I can generate certificates with Bouncycastle, but most examples seem to show examples of chains of trust, whereas in my case I have individual trusted keys. Also, all the examples I have seen deal with key-pairs, but I am only interested in the set of public keys provided. Is it possible to create a certificate containing only a public key?

Upvotes: 1

Views: 1463

Answers (1)

ursa
ursa

Reputation: 4601

Short answer: you cannot create certificate without private key.

Long answer: google "java create self signed certificate programmatically", e.g.: https://www.mayrhofer.eu.org/post/create-x509-certs-in-java/

Upvotes: 2

Related Questions