Paushchyk Julia
Paushchyk Julia

Reputation: 516

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"); for it, and I added Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); and compile 'org.bouncycastle:bcprov-jdk16:1.45' to gradle-file. So this project to run and work in Intellij Idea,

But if I generate .jar file and to run it, I have:

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).

Why my project in Intellij Idea - work! And in .jar-file - does not work?

Upvotes: 1

Views: 12013

Answers (2)

Sergey Nemchinov
Sergey Nemchinov

Reputation: 1616

Probably built jar file doesn't contain the dependency org.bouncycastle:bcprov-jdk16:1.45.
Please check this out Using Gradle to build a jar with dependencies

Upvotes: 0

Artjom B.
Artjom B.

Reputation: 61952

"RSA/NONE/PKCS1Padding" is not something that is available in default security providers of most JDKs. You can use "RSA/ECB/PKCS1Padding" which means the same thing, but uses the ECB name for backwards compatibility.

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:

Cipher.getInstance("RSA/NONE/PKCS1Padding", "BC");

Upvotes: 5

Related Questions