Search code examples
javasecuritycertificatebouncycastlex509

How to read issuer String from user's public key?


I want to read issuer String from user's public key with Bouncy Castle. Is there example code or something from which I can learn?


Solution

  • If you can obtain the certificate object, then you can do the following:

    ((X509Certificate) certificate).getIssuerX500Principal().getName();
    

    The public key itself does not have an issuer - only a certificate has. And you can get the public key from the certificate, but not vice-versa.

    Update: Since it appears that you want to verify the validity of your users, the public key alone does not provide this info. Public keys are used for encryption / digital signature verification, but for the rest of PKI you need the certificate. Actually, verifying the issuer that is written in the certificate gives you no guarantee whatsoever. You need to check:

    • the certificate revocation lists - i.e. whether the certificate is not revoked. This is done either via the provided CRLs or via the ocsp protocol.
    • the expiration of the certificate