bc-java icon indicating copy to clipboard operation
bc-java copied to clipboard

java.security.InvalidAlgorithmParameterException: only SM2ParameterSpec supported

Open TutuTang opened this issue 2 months ago • 3 comments

SM2ParameterSpec parameterSpec = new SM2ParameterSpec(userId); Signature signer = Signature.getInstance("SM3withSM2", "BC"); signer.setParameter(parameterSpec); An error is reported when the Spring Framework is upgraded from 5.x to 6.0 "java.security.InvalidAlgorithmParameterException: only SM2ParameterSpec supported"

The local ut is normal, but the deployment to the online environment is abnormal.

Can this information help analyze the root cause?

TutuTang avatar Oct 11 '25 09:10 TutuTang

The error message is from the BC provider, which is expecting an instance of org.bouncycastle.jcajce.spec.SM2ParameterSpec, so double-check that is the type in your code. If you are using the right type, then the problem is almost certainly a classpath issue; most likley cause would be multiple versions of the bouncycastle jars in the runtime classpath. You may need to check which version of the bouncycastle jars your spring dependencies are including.

peterdettman avatar Oct 12 '25 08:10 peterdettman

The error message is from the BC provider, which is expecting an instance of org.bouncycastle.jcajce.spec.SM2ParameterSpec, so double-check that is the type in your code. If you are using the right type, then the problem is almost certainly a classpath issue; most likley cause would be multiple versions of the bouncycastle jars in the runtime classpath. You may need to check which version of the bouncycastle jars your spring dependencies are including.

The version is 1.78.1. “the problem is almost certainly a classpath issue” Does this mean that Spring 5 is upgraded to 6, discarding javax and enabling the new jakarta namespace?

TutuTang avatar Oct 13 '25 02:10 TutuTang

I am saying Spring may include some bouncycastle jars, and upgrading from 5 to 6 may have changed the version of those bouncycastle jars and created a classpath conflict with the bouncycastle jars you are including directly.

peterdettman avatar Oct 13 '25 16:10 peterdettman