`JCE cannot authenticate the provider BC` when run

2019-05-17 22:29发布

问题:

In my scala project I use "org.bouncycastle" % "bcprov-jdk14" % "1.51" for cryptography.
If it test my project in Scala IDE it works fine. But once I make a JAR and try to run it via java -jar ... it throws an exception: Exception in thread "main" java.lang.SecurityException: JCE cannot authenticate the provider BC

I use https://github.com/sbt/sbt-assembly for making a JAR and here's my java -version output:

java version "1.7.0_72"
Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
Java HotSpot(TM) Server VM (build 24.72-b04, mixed mode)

When making a JAR I see this output:

[info] Merging files...
[warn] Merging 'META-INF/BCKEY.DSA' with strategy 'discard'
[warn] Merging 'META-INF/BCKEY.SF' with strategy 'discard'
[warn] Merging 'META-INF/LAMBDAWO.SF' with strategy 'discard'
[warn] Merging 'META-INF/MANIFEST.MF' with strategy 'discard'
[warn] Merging 'reference.conf' with strategy 'concat'
[warn] Merging 'rootdoc.txt' with strategy 'concat'
[warn] Strategy 'concat' was applied to 2 files
[warn] Strategy 'discard' was applied to 4 files

How can I fix this issue?