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?

1

2 Answers 2

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");
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.