From 9af565b940f850a74b5ae8ad895aa2e37bd41f8c Mon Sep 17 00:00:00 2001 From: Raphael-Joel Lim Date: Tue, 25 Jun 2024 22:41:20 -0700 Subject: [PATCH] Remove registration of bouncy castle as JCE provider (#2066) Signed-off-by: R-J Lim Co-authored-by: R-J Lim --- crypto/src/main/java/org/web3j/crypto/Keys.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/crypto/src/main/java/org/web3j/crypto/Keys.java b/crypto/src/main/java/org/web3j/crypto/Keys.java index b29e4f9db..48de97583 100644 --- a/crypto/src/main/java/org/web3j/crypto/Keys.java +++ b/crypto/src/main/java/org/web3j/crypto/Keys.java @@ -19,7 +19,6 @@ import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.SecureRandom; -import java.security.Security; import java.security.spec.ECGenParameterSpec; import java.util.Arrays; @@ -40,12 +39,7 @@ public class Keys { public static final int ADDRESS_LENGTH_IN_HEX = ADDRESS_SIZE >> 2; static final int PUBLIC_KEY_LENGTH_IN_HEX = PUBLIC_KEY_SIZE << 1; public static final int PRIVATE_KEY_LENGTH_IN_HEX = PRIVATE_KEY_SIZE << 1; - - static { - if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) == null) { - Security.addProvider(new BouncyCastleProvider()); - } - } + private static final BouncyCastleProvider BC_PROVIDER = new BouncyCastleProvider(); private Keys() {} @@ -68,7 +62,7 @@ static KeyPair createSecp256k1KeyPair(SecureRandom random) NoSuchAlgorithmException, InvalidAlgorithmParameterException { - KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("ECDSA", "BC"); + KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("ECDSA", BC_PROVIDER); ECGenParameterSpec ecGenParameterSpec = new ECGenParameterSpec("secp256k1"); if (random != null) { keyPairGenerator.initialize(ecGenParameterSpec, random);