Skip to content

Commit

Permalink
Add BouncyCastleProvider as security provider to prevent NPE (apache#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Masahiro Sakamoto authored Feb 18, 2021
1 parent 2e08766 commit 28585e2
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Security;
import java.security.spec.InvalidKeySpecException;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -123,6 +124,11 @@ public class MessageCryptoBc implements MessageCrypto<MessageMetadata, MessageMe

// Initial seed
secureRandom.nextBytes(new byte[IV_LEN]);

// Add provider only if it's not in the JVM
if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) {
Security.addProvider(new BouncyCastleProvider());
}
}

public MessageCryptoBc(String logCtx, boolean keyGenNeeded) {
Expand Down

0 comments on commit 28585e2

Please sign in to comment.