Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ECDSA with SHA256 in Bouncy castle throws No Such Algorithm Exception

I am trying to generate a signature using ECDSA with SHA256 in Bouncy Castle as follows,

  1. I add the provider in the begining
  2. I have built the ECPrivatekey
  3. Signature s_oSignature = Signature.getInstance("SHA256withECDSA",     
    BouncyCastleProvider.PROVIDER_NAME);
    

but step 3 throws "java.security.NoSuchAlgorithmException: no such algorithm: SHA256withECDSA for provider BC".

But same "SHA256withECDSA" thing when replaced with "SHA1withECDSA" prceeds without any exception.

How is it possible? I am using "bcprov-jdk14-121.jar".

Can any one please help me as I have been struggling for a long time?

like image 657
Aslam Avatar asked Nov 22 '25 11:11

Aslam


1 Answers

I've never encountered this problem but here are a few things you can try.

  1. make sure you have the Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files installed and configured (download here at the bottom of the page)
  2. try using the latest release of BouncyCastle and installing it as a provider in the runtime and not on-the-fly within the program

This problem is extremely odd as SHA256withECDSA is clearly listed in the specifications so it only leaves the option to try all possible options no matter how unlikely they are to help.

like image 133
Jim Avatar answered Nov 24 '25 00:11

Jim