SecretKeyFactory.getInstance() throws exception for all algorithms in unit tests
java, powermock, security
Solution
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.
Problem
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?