[英]java.security.NoSuchAlgorithmException: Cannot find any provider supporting RSA/NONE/PKCS1Padding in jar-file
I do to decrypt and encrypt RSA, I use Cipher.getInstance("RSA/NONE/PKCS1Padding");
我做解密和加密 RSA,我使用Cipher.getInstance("RSA/NONE/PKCS1Padding");
for it, and I added Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
为此,我添加了Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
and compile 'org.bouncycastle:bcprov-jdk16:1.45'
to gradle-file.并将compile 'org.bouncycastle:bcprov-jdk16:1.45'
为 gradle 文件。 So this project to run and work in Intellij Idea,所以这个项目在 Intellij Idea 中运行和工作,
But if I generate .jar file and to run it, I have:但是如果我生成 .jar 文件并运行它,我有:
java.security.NoSuchAlgorithmException: Cannot find any provider supporting RSA/NONE/PKCS1Padding
at javax.crypto.Cipher.getInstance(Cipher.java:540)
(generated .jar by ShadowJar task of gradle). (由 gradle 的 ShadowJar 任务生成的 .jar)。
Why my project in Intellij Idea - work!为什么我在 Intellij Idea 中的项目 - 工作! And in .jar-file - does not work?在 .jar 文件中 - 不起作用?
"RSA/NONE/PKCS1Padding"
is not something that is available in default security providers of most JDKs. "RSA/NONE/PKCS1Padding"
在大多数 JDK 的默认安全提供程序中不可用。 You can use "RSA/ECB/PKCS1Padding"
which means the same thing, but uses the ECB name for backwards compatibility.您可以使用"RSA/ECB/PKCS1Padding"
这意味着相同的事情,但使用 ECB 名称以实现向后兼容性。
The BouncyCastle provider does give access to "RSA/NONE/PKCS1Padding"
, but then you need to query it specifically, because adding a provider to the provider list doesn't make it a default provider: BouncyCastle 提供程序确实可以访问"RSA/NONE/PKCS1Padding"
,但是您需要专门查询它,因为将提供程序添加到提供程序列表不会使其成为默认提供程序:
Cipher.getInstance("RSA/NONE/PKCS1Padding", "BC");
Probably built jar file doesn't contain the dependency org.bouncycastle:bcprov-jdk16:1.45
.可能构建的 jar 文件不包含依赖项org.bouncycastle:bcprov-jdk16:1.45
。
Please check this out Using Gradle to build a jar with dependencies请查看Using Gradle to build a jar with dependencies
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.