Repository: quarkusio/quarkus
Issue: Security provider BC + Native Mode not working in Quarkus v2.0

### Describe the bug

Since upgrading Quarkus to version 2.0 the security provider Bouncy Castle seems not supported anymore. 

**Quarkus Platform (working):** 1.13.0.Final
**Quarkus Platform (not working):** 2.0.1.Final

_Related Dependencies:_
```
 <dependency>
      <groupId>org.bouncycastle</groupId>
      <artifactId>bcprov-jdk15on</artifactId>
  </dependency>
```

Register Security Provider in _application.properties_
```
### Security ###
quarkus.security.security-providers=BC
```

According to migration guide (https://github.com/quarkusio/quarkus/wiki/Migration-Guide-2.0) no additional changes required. 


### Expected behavior

BouncCastle should work without modifications as it did in previous Quarkus version.

### Actual behavior

Executing native image works basically but if a method will be called requiring Bouncy Castle an exception will be thrown: 
* NoSuchAlgorithm
* ClassNotFound

### How to Reproduce?

* update quarkus version in pom.xml to 2.0.1.Final
* compile native image
* run application and call method requiring Bounc Castle as security provider
* retrieve NoSuchAlgorithm or ClassNotFound exception

### Output of `uname -a` or `ver`

_No response_

### Output of `java -version`

11.0.11

### GraalVM version (if different from Java)

GraalVM 21.1.0

### Quarkus version or git rev

2.0.1.Final

### Build tool (ie. output of `mvnw --version` or `gradlew --version`)

maven

### Additional information

Building native image using following command:

`mvn -f myapp-xxx/pom.xml clean package -Pnative -Dgoogle.cloud.credentials=*** -Dquarkus.container-image.username=oauth2accesstoken -Dquarkus.container-image.*** -Dquarkus.native.container-build=true -Dquarkus.container-image.build=true -Dquarkus.container-image.push=true -Dquarkus.profile=stage -DskipTests`


Full Stack Trace

`java.security.NoSuchAlgorithmException: class configured for KeyPairGenerator (provider: BC) cannot be found.
	at java.security.Provider$Service.getImplClass(Provider.java:1933)
	at java.security.Provider$Service.newInstance(Provider.java:1894)
	at sun.security.jca.GetInstance.getInstance(GetInstance.java:236)
	at sun.security.jca.GetInstance.getInstance(GetInstance.java:206)
	at java.security.KeyPairGenerator.getInstance(KeyPairGenerator.java:300)
	at at.ebs.iot.workerservice.service.DatabaseService.generateKeyPair(DatabaseService.java:55)
	at at.ebs.iot.workerservice.service.DatabaseService.updateDeviceKeyPool(DatabaseService.java:37)
	at at.ebs.iot.workerservice.service.DatabaseService_Subclass.updateDeviceKeyPool$$superforward1(DatabaseService_Subclass.zig:101)
	at at.ebs.iot.workerservice.service.DatabaseService_Subclass$$function$$1.apply(DatabaseService_Subclass$$function$$1.zig:24)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
	at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.invokeInOurTx(TransactionalInterceptorBase.java:127)
	at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.invokeInOurTx(TransactionalInterceptorBase.java:100)
	at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired.doIntercept(TransactionalInterceptorRequired.java:32)
	at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorBase.intercept(TransactionalInterceptorBase.java:53)
	at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired.intercept(TransactionalInterceptorRequired.java:26)
	at io.quarkus.narayana.jta.runtime.interceptor.TransactionalInterceptorRequired_Bean.intercept(TransactionalInterceptorRequired_Bean.zig:340)
	at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
	at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
	at at.ebs.iot.workerservice.service.DatabaseService_Subclass.updateDeviceKeyPool(DatabaseService_Subclass.zig:157)
	at at.ebs.iot.workerservice.service.DatabaseService_Bean.create(DatabaseService_Bean.zig:291)
	at at.ebs.iot.workerservice.service.DatabaseService_Bean.create(DatabaseService_Bean.zig:307)
	at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:96)
	at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:29)
	at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:26)
	at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:26)
	at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
	at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:26)
	at io.quarkus.arc.impl.ClientProxies.getApplicationScopedDelegate(ClientProxies.java:17)
	at at.ebs.iot.workerservice.service.DatabaseService_ClientProxy.arc$delegate(DatabaseService_ClientProxy.zig:67)
	at at.ebs.iot.workerservice.service.DatabaseService_ClientProxy.arc_contextualInstance(DatabaseService_ClientProxy.zig:82)
	at at.ebs.iot.workerservice.service.DatabaseService_Observer_Synthetic_d70cd75bf32ab6598217b9a64a8473d65e248c05.notify(DatabaseService_Observer_Synthetic_d70cd75bf32ab6598217b9a64a8473d65e248c05.zig:94)
	at io.quarkus.arc.impl.EventImpl$Notifier.notifyObservers(EventImpl.java:300)
	at io.quarkus.arc.impl.EventImpl$Notifier.notify(EventImpl.java:282)
	at io.quarkus.arc.impl.EventImpl.fire(EventImpl.java:70)
	at io.quarkus.arc.runtime.ArcRecorder.fireLifecycleEvent(ArcRecorder.java:128)
	at io.quarkus.arc.runtime.ArcRecorder.handleLifecycleEvents(ArcRecorder.java:97)
	at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent1144526294.deploy_0(LifecycleEventsBuildStep$startupEvent1144526294.zig:87)
	at io.quarkus.deployment.steps.LifecycleEventsBuildStep$startupEvent1144526294.deploy(LifecycleEventsBuildStep$startupEvent1144526294.zig:40)
	at io.quarkus.runner.ApplicationImpl.doStart(ApplicationImpl.zig:864)
	at io.quarkus.runtime.Application.start(Application.java:101)
	at io.quarkus.runtime.ApplicationLifecycleManager.run(ApplicationLifecycleManager.java:101)
	at io.quarkus.runtime.Quarkus.run(Quarkus.java:66)
	at io.quarkus.runtime.Quarkus.run(Quarkus.java:42)
	at io.quarkus.runtime.Quarkus.run(Quarkus.java:119)
	at io.quarkus.runner.GeneratedMain.main(GeneratedMain.zig:29)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jcajce.provider.asymmetric.ec.KeyPairGeneratorSpi$EC
	at com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:64)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:290)
	at java.security.Provider$Service.getImplClass(Provider.java:1920)
	... 45 more`

Changed files:
extensions/security/deployment/src/main/java/io/quarkus/security/deployment/SecurityProcessor.java
integration-tests/bouncycastle/src/test/java/io/quarkus/it/bouncycastle/BouncyCastleTestCase.java
integration-tests/bouncycastle/src/main/java/io/quarkus/it/bouncycastle/BouncyCastleEndpoint.java

diff --git a/extensions/security/deployment/src/main/java/io/quarkus/security/deployment/SecurityProcessor.java b/extensions/security/deployment/src/main/java/io/quarkus/security/deployment/SecurityProcessor.java
index 726419f7d97..d6bd449991c 100644
--- a/extensions/security/deployment/src/main/java/io/quarkus/security/deployment/SecurityProcessor.java
+++ b/extensions/security/deployment/src/main/java/io/quarkus/security/deployment/SecurityProcessor.java
@@ -146,6 +146,12 @@ private static void prepareBouncyCastleProvider(BuildProducer<ReflectiveClassBui
         reflection.produce(new ReflectiveClassBuildItem(true, true,
                 isFipsMode ? SecurityProviderUtils.BOUNCYCASTLE_FIPS_PROVIDER_CLASS_NAME
                         : SecurityProviderUtils.BOUNCYCASTLE_PROVIDER_CLASS_NAME));
+        reflection.produce(new ReflectiveClassBuildItem(true, true,
+                "org.bouncycastle.jcajce.provider.asymmetric.ec.KeyPairGeneratorSpi"));
+        reflection.produce(new ReflectiveClassBuildItem(true, true,
+                "org.bouncycastle.jcajce.provider.asymmetric.ec.KeyPairGeneratorSpi$EC"));
+        reflection.produce(new ReflectiveClassBuildItem(true, true,
+                "org.bouncycastle.jcajce.provider.asymmetric.rsa.KeyPairGeneratorSpi"));
         reflection.produce(new ReflectiveClassBuildItem(true, true,
                 "org.bouncycastle.jcajce.provider.asymmetric.rsa.PSSSignatureSpi"));
         reflection.produce(new ReflectiveClassBuildItem(true, true,
diff --git a/integration-tests/bouncycastle/src/main/java/io/quarkus/it/bouncycastle/BouncyCastleEndpoint.java b/integration-tests/bouncycastle/src/main/java/io/quarkus/it/bouncycastle/BouncyCastleEndpoint.java
index 153318831b2..b2b2bd35649 100644
--- a/integration-tests/bouncycastle/src/main/java/io/quarkus/it/bouncycastle/BouncyCastleEndpoint.java
+++ b/integration-tests/bouncycastle/src/main/java/io/quarkus/it/bouncycastle/BouncyCastleEndpoint.java
@@ -1,5 +1,6 @@
 package io.quarkus.it.bouncycastle;
 
+import java.security.KeyPairGenerator;
 import java.security.Security;
 import java.security.Signature;
 import java.util.Arrays;
@@ -26,4 +27,20 @@ public String checkSHA256withRSAandMGF1() throws Exception {
         Signature.getInstance("SHA256withRSAandMGF1", "BC");
         return "success";
     }
+
+    @GET
+    @Path("generateEcKeyPair")
+    public String generateEcKeyPair() throws Exception {
+        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("EC", "BC");
+        keyPairGenerator.generateKeyPair();
+        return "success";
+    }
+
+    @GET
+    @Path("generateRsaKeyPair")
+    public String generateRsaKeyPair() throws Exception {
+        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA", "BC");
+        keyPairGenerator.generateKeyPair();
+        return "success";
+    }
 }
diff --git a/integration-tests/bouncycastle/src/test/java/io/quarkus/it/bouncycastle/BouncyCastleTestCase.java b/integration-tests/bouncycastle/src/test/java/io/quarkus/it/bouncycastle/BouncyCastleTestCase.java
index 0f94b08af0e..6cdf2a18795 100644
--- a/integration-tests/bouncycastle/src/test/java/io/quarkus/it/bouncycastle/BouncyCastleTestCase.java
+++ b/integration-tests/bouncycastle/src/test/java/io/quarkus/it/bouncycastle/BouncyCastleTestCase.java
@@ -30,4 +30,24 @@ public void testSHA256withRSAandMGF1() {
                 .body(equalTo("success"));
     }
 
+    @Test
+    public void testGenerateEcKeyPair() {
+        RestAssured.given()
+                .when()
+                .get("/jca/generateEcKeyPair")
+                .then()
+                .statusCode(200)
+                .body(equalTo("success"));
+    }
+
+    @Test
+    public void testGenerateRsaKeyPair() {
+        RestAssured.given()
+                .when()
+                .get("/jca/generateRsaKeyPair")
+                .then()
+                .statusCode(200)
+                .body(equalTo("success"));
+    }
+
 }