ashy143
ashy143

Reputation: 169

EncryptionInitializationException using PowerMockRunner and not with MockitoJUnitRunner

When I test below function using MockitoJunitRunner it works fine as expected. But when I am running the same test using PowerMockRunner I get following exception:

org.jasypt.exceptions.EncryptionInitializationException:

java.security.NoSuchAlgorithmException: PBEWithMD5AndDES SecretKeyFactory not available
 functionToBeTested() {
         Encryptor.encrypt(this.getIgvToken(), "IGVKEY123");  
    }

I am wondering why it throws exception when I use PowerMockRunner. Here are my dependencies:

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-module-junit4</artifactId>
        <version>1.6.5</version>
    </dependency>

Upvotes: 0

Views: 832

Answers (2)

blu3
blu3

Reputation: 123

I was facing the exact problem but unfortunately this solution couldn't help me. It got resolved by adding @PowerMockIgnore ("javax.crypto.*") in my class as given in the following link:

SecretKeyFactory.getInstance() throws exception for all algorithms in unit tests

Upvotes: 3

ashy143
ashy143

Reputation: 169

Other than class under test also add annotation @PrepareForTest({Encryptor.class}).

Upvotes: 0

Related Questions