Search code examples
javasslbouncycastleelliptic-curveecdsa

How to sign the Certificates with Elliptic curve private keys and ECDSA algorithm?


I am able to sign the certificates using bouncy castle with RSA private Keys and "SHA256withRSA " algorithm. I have used below link for reference to achieve this. Sign CSR using Bouncy Castle

Now I have my CAs with Elliptic Curve keys signed with ECDSA. Hence I want to sign the certificates with EC key and "SHA256withECDSA" algorithm by these CAs. However I am stuck at below snippet specific to RSA key, I want to use EC key.

ContentSigner sigGen = new BcRSAContentSignerBuilder(sigAlgId, digAlgId).build(privateKeyParam);

Please help me how we can achieve Certificate signing with ECDSA and EC keys


Solution

  • Below code used to sign the certificates with EC private keys

    ContentSigner sigGen = new JcaContentSignerBuilder("SHA256withECDSA").build(new JcaPEMKeyConverter().getPrivateKey(PrivateKeyInfo));