привет, я пытался перевести некоторый код Spring в vertx, и у меня есть этот фрагмент кода, который использует надувной замок
private SecretKey calculateSecureSymetricKey(Key privateKey, Key receivedPublicKey) throws Exception {
BouncyCastleProvider bouncyCastleProvider = new BouncyCastleProvider();
KeyAgreement keyAgreement ;
try {
keyAgreement = KeyAgreement.getInstance("ECDH", bouncyCastleProvider);
} catch (Exception e) {
System.out.println("failed in custom exception");
System.out.println("==============================");
e.printStackTrace();
System.out.println("==============================");
throw new Exception(e);
}
keyAgreement.init(privateKey);
keyAgreement.doPhase(receivedPublicKey, true);
byte[] sharedSecret = keyAgreement.generateSecret();
ASN1ObjectIdentifier oid = NISTObjectIdentifiers.id_aes256_CBC;
int keySize = 256;
DHKDFParameters params = new DHKDFParameters(oid, keySize, sharedSecret, null);
ECDHKEKGenerator kdf = new ECDHKEKGenerator(DigestFactory.createSHA256());
kdf.init(params);
byte[] keyBytes = new byte[keySize / 8];
kdf.generateBytes(keyBytes, 0, keyBytes.length);
SecretKeySpec aes = new SecretKeySpec(keyBytes, "AES");
return aes;
}
теперь, когда я запускаю его в своей среде IDE (eclipse), он работает нормально, но когда я использую maven, чтобы превратить это в банку с этим pom.xml
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.62</version>
<!-- <version>1.59</version> -->
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<!-- <version>1.59</version> -->
<version>1.62</version>
</dependency>
<!-- some more pom here that I can post if you think it's relevant -->
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>mytest.Main</mainClass>
</manifest>
</archive>
<!-- <appendAssemblyId>false</appendAssemblyId> -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Я запускаю mvn clean install
и пытаюсь запустить банку, я получаю это исключение
java.lang.SecurityException: JCE cannot authenticate the provider BC
at java.base/javax.crypto.JceSecurity.getInstance(JceSecurity.java:143)
at java.base/javax.crypto.KeyAgreement.getInstance(KeyAgreement.java:278)
at deanew.service.KeyExchangeService.calculateSecureSymetricKey(KeyExchangeService.java:93)
at deanew.service.KeyExchangeService.generateSecretKeyFromResponse(KeyExchangeService.java:84)
at deanew.service.DeaNewService.getSaredSecretKey(DeaNewService.java:82)
at deanew.service.DeaNewService.getPersonInfo(DeaNewService.java:177)
at deanew.service.DeaNewService.getOldPersonInfo(DeaNewService.java:94)
at deanew.service.DeaServiceImpl.lambda$deaByPin$0(DeaServiceImpl.java:54)
at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$2(ContextImpl.java:316)
at io.vertx.core.impl.TaskQueue.run(TaskQueue.java:76)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.util.jar.JarException: file:/C:/Users/97252/eclipse-workspace_zukit_se/mytest/target/myTest-0.0.1
-SNAPSHOT-jar-with-dependencies.jar has unsigned entries - dea/dea.jks
at java.base/javax.crypto.JarVerifier.verifySingleJar(JarVerifier.java:459)
at java.base/javax.crypto.JarVerifier.verifyJars(JarVerifier.java:314)
at java.base/javax.crypto.JarVerifier.verify(JarVerifier.java:257)
at java.base/javax.crypto.ProviderVerifier.verify(ProviderVerifier.java:129)
at java.base/javax.crypto.JceSecurity.verifyProvider(JceSecurity.java:189)
at java.base/javax.crypto.JceSecurity.getVerificationResult(JceSecurity.java:215)
at java.base/javax.crypto.JceSecurity.getInstance(JceSecurity.java:139)
... 13 more
так что мои вопросы
- кто-нибудь знает, в чем проблема с этим кодом? или если это
- это пример кода, просто чтобы изолировать проблему и посмотреть, смогу ли я скомпилировать банку и передать ее в качестве дополнения к основному проекту, но pom.xml, который я использую в основном приложении, использует
maven-shade-plugin
вместоmaven-assembly-plugin
, который я использую в этом примере это будет работать даже с vertx? быть
Я думаю, что ясно объяснил, но если я этого не сделал, пожалуйста, скажите мне спасибо заранее
РЕДАКТИРОВАТЬ:
до сих пор я также пытался загрузить банки и добавить их в качестве зависимости с такой системой областей видимости.
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<scope> system</scope>
<systemPath>${basedir}/src/lib/bcpkix-jdk15on-1.63.jar</systemPath>
<version>1.63</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<scope> system</scope>
<systemPath>${basedir}/src/lib/bcprov-jdk15to18-1.63.jar</systemPath>
<version>1.63</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>${vertx.version}</version>
</dependency>
и я попытался добавить sulotion Майкла Фера, так что теперь сборка выглядит так
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<target name="-post-jar">
<jar jarfile="">
<zipfileset src="${dist.jar}" excludes="META-INF/*" />
<zipfileset src="/src/lib/bcpkix-jdk15on-1.63.jar"
excludes="META-INF/*" />
<zipfileset src="/src/lib/bcprov-jdk15to18-1.63.jar"
excludes="META-INF/*" />
</jar>
</target>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifest>
<mainClass>mytest.Main</mainClass>
</manifest>
</archive>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
и до сих пор те же проблемы любые мысли
и спасибо заранее