SecretKeyFactory.getInstance()引发单元测试中所有算法的异常 [英] SecretKeyFactory.getInstance() throws exception for all algorithms in unit tests

查看:811
本文介绍了SecretKeyFactory.getInstance()引发单元测试中所有算法的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,无论指定哪种算法,在调用SecretKeyFactory.getInstance()时我总是在单元测试中遇到异常。例如:

  SecretKeyFactory.getInstance( PBEWITHMD5ANDDES)

com.mhe.connect.util .EncryptionException:java.security.NoSuchAlgorithmException:PBEWITHMD5ANDDES SecretKeyFactory不可用

同时,我看到Security.getProviders()返回我所需的算法:

  SECRETKEYFACTORY.DESEDE SunJCE 
SECRETKEYFACTORY.PBEWITHMD5ANDDES SunJCE
SECRETKEYFACTORY.DES SUNJCE
SECRETKEYFACTORY.PBEWITHMD5和三位一体的SunJCE
SECRETKEYFACTORY.PBKDF2WITHHMACSHA1 SunJCE
SECRETKEYFACTORY.PBEWITHSHA1ANDDESEDE SunJCE
$ PB $ b SEC_KEY1 p $ p>

这仅在单元测试(来自Maven或IDE)中发生,并且如果代码在Jetty下运行(从同一Maven / JDK运行),效果很好。



这种行为的原因可能是什么?

解决方案

今天遇到同样的问题。通过在类中添加 @PowerMockIgnore( javax.crypto。*)来解决。



有人知道吗是否可以全局忽略此软件包?我不想将其添加到执行该程序包中的代码的每个类中。


By some reason I always get exception in unit test when calling SecretKeyFactory.getInstance() no matter what algorithm is specified. For example:

SecretKeyFactory.getInstance("PBEWITHMD5ANDDES")

com.mhe.connect.util.EncryptionException: java.security.NoSuchAlgorithmException: PBEWITHMD5ANDDES SecretKeyFactory not available

At the same time, I see that Security.getProviders() returns me needed algorithms:

SECRETKEYFACTORY.DESEDE SunJCE
SECRETKEYFACTORY.PBEWITHMD5ANDDES SunJCE
SECRETKEYFACTORY.DES SunJCE
SECRETKEYFACTORY.PBEWITHMD5ANDTRIPLEDES SunJCE
SECRETKEYFACTORY.PBKDF2WITHHMACSHA1 SunJCE
SECRETKEYFACTORY.PBEWITHSHA1ANDDESEDE SunJCE
SECRETKEYFACTORY.PBEWITHSHA1ANDRC2_40 SunJCE

This happens only in unit tests (from Maven, or IDE) and works fine if code is running under Jetty (that is run from same Maven/JDK).

What could be the reason for such behavior?

解决方案

Ran into the same issue today. Solved it by adding @PowerMockIgnore ("javax.crypto.*") to the class.

Does anyone know if I can globally ignore this package? I don't want to add it to every class that executes code from that package.

这篇关于SecretKeyFactory.getInstance()引发单元测试中所有算法的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆