1

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?

Artjom B.
  • 61,146
  • 24
  • 125
  • 222
Paushchyk Julia
  • 516
  • 3
  • 8
  • 24
  • Related: [RSA/NONE/PKCS1Padding giving error as java.security.NoSuchAlgorithmException](http://stackoverflow.com/questions/20961481/rsa-none-pkcs1padding-giving-error-as-java-security-nosuchalgorithmexception) – Artjom B. Jan 08 '16 at 09:56

2 Answers2

5

"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");
Artjom B.
  • 61,146
  • 24
  • 125
  • 222
0

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

Sergey Nemchinov
  • 1,348
  • 15
  • 21