Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 721665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:54:00+00:00 2026-05-14T05:54:00+00:00

Where can I find a RSA encrypt example that does not use NoPadding? –update

  • 0

Where can I find a RSA encrypt example that does not use “NoPadding”?

–update

Better: how to make this SSCCE run correctly without throw the “too much data for RSA block” exception?

import java.math.BigInteger;
import java.security.KeyFactory;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.RSAPrivateKeySpec;
import java.security.spec.RSAPublicKeySpec;

import javax.crypto.Cipher;

/**
 * Basic RSA example.
 */
public class TestRSA {

    public static void main(String[] args) throws Exception {

 byte[] input = new byte[100];

 Cipher cipher = Cipher.getInstance("RSA/None/NoPadding", "BC");
 KeyFactory keyFactory = KeyFactory.getInstance("RSA", "BC");

 // create the keys

 RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(new BigInteger("d46f473a2d746537de2056ae3092c451",
  16), new BigInteger("11", 16));
 RSAPrivateKeySpec privKeySpec = new RSAPrivateKeySpec(new BigInteger(
  "d46f473a2d746537de2056ae3092c451", 16), new BigInteger("57791d5430d593164082036ad8b29fb1",
  16));

 RSAPublicKey pubKey = (RSAPublicKey) keyFactory.generatePublic(pubKeySpec);
 RSAPrivateKey privKey = (RSAPrivateKey) keyFactory.generatePrivate(privKeySpec);

 // encryption step

 cipher.init(Cipher.ENCRYPT_MODE, pubKey);

 byte[] cipherText = cipher.doFinal(input);

 // decryption step

 cipher.init(Cipher.DECRYPT_MODE, privKey);

 byte[] plainText = cipher.doFinal(cipherText);

    }
}

–update: about loop

Using:

 byte[] cipherText = new byte[input.length];
 for (int i = 0; i < input.length; i++) {
     byte[] singleByteArray = new byte[] { input[i] };
     cipherText[i] = cipher.doFinal(singleByteArray)[0];
 }

does not work fine. For a unknown reason the cipherText became full of zeros – even if the input is an array of 0x03.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:54:00+00:00Added an answer on May 14, 2026 at 5:54 am

    The Sun Providers Documentation for the SunJCE provider tells you what padding specifications are allowed in the Cipher.getInstance() argument. Try Cipher.getInstance("RSA/ECB/PKCS1PADDING");

    EDIT:
    It is not a padding issue, it is more that you have a misunderstanding of how RSA is used in cryptography. You can either 1) make the modulus bigger than the data, 2) use a Hybrid cryptosystem, or 3) least desirable is to manually break up the input into chunks that are each smaller than the modulus. If you are going to use PKCS1 padding (which is generally recommended), then the input must be not larger than n-11 bytes in length, where n is the number of bytes needed to store the RSA modulus.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 355k
  • Answers 355k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Using a regex to parse HTML is not advisable (think… May 14, 2026 at 8:41 am
  • Editorial Team
    Editorial Team added an answer Code in the constructor runs immediately when you create the… May 14, 2026 at 8:41 am
  • Editorial Team
    Editorial Team added an answer You have a unique file descriptor, so you don't have… May 14, 2026 at 8:41 am

Related Questions

I am trying to implement a PKI verification scheme, where a message string is
Is there any way to find all the empty catch blocks inside Java code?
Recently I've been unable to clone or push to github, and I'm trying to
Where can I find a good tutorial on learning ASP.NET MVC using VB.net 2008
Where can I find a list of all types of bsd style socket errors?

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.