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 8869257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:26:50+00:00 2026-06-14T17:26:50+00:00

I am trying to implement PKI. I want encrypt large string using RSA in

  • 0

I am trying to implement PKI. I want encrypt large string using RSA in java without using bouncy castle. Problem i am getting is Data must not be longer than 117 bytes. I tried seaching for the solution where i failed. I am newbie in this encryption. Please help me out by giving an large string as an example and explain it.

  • 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-06-14T17:26:51+00:00Added an answer on June 14, 2026 at 5:26 pm

    You cannot use an RSA encryption decryption on more than approx 128 bytes at a time. You must split up the data and do it in a loop pretty much writing the bytes to String/Array as you go. If your only problem is the size of the data, you probably don’t have much more to go. Just splitting the data.

    A great example, possibly more complete for you, dealing with strings larger than 128 bytes: http://www.stellarbuild.com/blog/article/encrypting-and-decrypting-large-data-using-java-and-rsa

    If you need more explanation on RSA encryption in general:

    The following code demonstrates how to use KeyPairGenerator to generate an RSA key-pair in Java:

    // Get an instance of the RSA key generator
    KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
    // Generate the keys — might take sometime on slow computers
    KeyPair myPair = kpg.generateKeyPair();
    

    This will give you a KeyPair object, which holds two keys: a private and a public. In order to make use of these keys, you will need to create a Cipher object, which will be used in combination with SealedObject to encrypt the data that you are going to end over the network. Here’s how you do that:

    // Get an instance of the Cipher for RSA encryption/decryption
    Cipher c = Cipher.getInstance("RSA");
    // Initiate the Cipher, telling it that it is going to Encrypt, giving it the public key
    c.init(Cipher.ENCRYPT_MODE, myPair.getPublic()); 
    

    After initializing the Cipher, we’re ready to encrypt the data. Since after encryption the resulting data will not make much sense if you see them “naked”, we have to encapsulate them in another Object. Java provides this, by the SealedObject class. SealedObjects are containers for encrypted objects, which encrypt and decrypt their contents with the help of a Cipher object.

    The following example shows how to create and encrypt the contents of a SealedObject:

    // Create a secret message
    String myMessage = new String("Secret Message");
    // Encrypt that message using a new SealedObject and the Cipher we created before
    SealedObject myEncryptedMessage= new SealedObject( myMessage, c);
    

    The resulting object can be sent over the network without fear, since it is encrypted. The only one who can decrypt and get the data, is the one who holds the private key. Normally, this should be the server. In order to decrypt the message, we’ll need to re-initialize the Cipher object, but this time with a different mode, decrypt, and use the private key instead of the public key.

    This is how you do this in Java:

    // Get an instance of the Cipher for RSA encryption/decryption
    Cipher dec = Cipher.getInstance("RSA");
    // Initiate the Cipher, telling it that it is going to Decrypt, giving it the private key
    dec.init(Cipher.DECRYPT_MODE, myPair.getPrivate());
    

    Now that the Cipher is ready to decrypt, we must tell the SealedObject to decrypt the held data.

    // Tell the SealedObject we created before to decrypt the data and return it
    String message = (String) myEncryptedMessage.getObject(dec);
    System.out.println("foo = "+message);
    

    Beware when using the getObject method, since it returns an instance of an Object (even if it is actually an instance of String), and not an instance of the Class that it was before encryption, so you’ll have to cast it to its prior form.

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

Sidebar

Related Questions

I am trying to implement a PKI verification scheme, where a message string is
Trying to implement 3-layer (not: tier, I just want to separate my project logically,
I'm trying implement a bracket in my program (using C#/.NET MVC) and I am
Trying to implement search with Sunspot Gem wich is using Solr.Fulltext search works fine
I am trying implement Unblock me Puzzle. i want to change image position from
trying to implement a dialog-box style behaviour using a separate div section with all
Trying to implement clean URLs (without .form, .do, etc.) with Spring MVC 3.0 (actually
I'm trying implement a way to recursively template using jsRender. The issue is, my
Trying to implement simple error handling without adding buku try / except statements to
trying to implement a multiplayer. Using the sample from Game Center - Sending and

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.