在Grails 2.5.0中找不到BouncyCastleProvider类

时间:2015-06-21 13:48:01

标签: grails classloader bouncycastle

我有一个Grails项目,我想在其中使用Bouncycastle来计算字符串的Sha512哈希值。

当我致电Security.addProvider(new BouncyCastleProvider())时,收到以下错误消息:

| Error 2015-06-21 15:34:53,242 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener  - Error initializing the application: org/bouncycastle/jce/provider/BouncyCastleProvider
Message: org/bouncycastle/jce/provider/BouncyCastleProvider
Line | Method
->>   49 | doCall                           in BootStrap$_closure1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    327 | evaluateEnvironmentSpecificBlock in grails.util.Environment
|    320 | executeForEnvironment . . . . .  in     ''
|    296 | executeForCurrentEnvironment     in     ''
|    262 | run . . . . . . . . . . . . . .  in java.util.concurrent.FutureTask
|   1145 | runWorker                        in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . . . . . . . . . . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run                              in java.lang.Thread
Caused by ClassNotFoundException: org.bouncycastle.jce.provider.BouncyCastleProvider
->>  366 | run                              in java.net.URLClassLoader$1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|    355 | run                              in     ''
|    354 | findClass . . . . . . . . . . .  in java.net.URLClassLoader
|    425 | loadClass                        in java.lang.ClassLoader
|     49 | doCall . . . . . . . . . . . . . in BootStrap$_closure1
|    327 | evaluateEnvironmentSpecificBlock in grails.util.Environment
|    320 | executeForEnvironment . . . . .  in     ''
|    296 | executeForCurrentEnvironment     in     ''
|    262 | run . . . . . . . . . . . . . .  in java.util.concurrent.FutureTask
|   1145 | runWorker                        in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . . . . . . . . . . . .  in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run                              in java.lang.Thread

在我的IDE(IntelliJ)中,导入import org.bouncycastle.jce.provider.BouncyCastleProvider似乎已解决,我可以导航到该类的位置。

为什么执行应用程序时找不到BouncyCastle类?

1 个答案:

答案 0 :(得分:0)

您是否在正在使用的JRE的JCE安全策略文件中添加了提供程序的条目?

JAVA_HOME\jre\lib\security\java.security

n比已存在的最后一个条目多一个

security.provider.n=org.bouncycastle.jce.provider.BouncyCastleProvider

http://bouncycastle.org/wiki/display/JA1/Provider+Installation