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

  • SEARCH
  • Home
  • 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 8118195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:24:17+00:00 2026-06-06T04:24:17+00:00

I am having a problem decrypting a file using RSA public key decryption. My

  • 0

I am having a problem decrypting a file using RSA public key decryption. My process is to receive the xml file, encrypt the content, and write it back to the same file. Another function decrypts the content. My source code is:

public void decryptFile(String fileName,PrivateKey privateKey) throws Exception {
    Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
    cipher.init(Cipher.DECRYPT_MODE, privateKey);
    FileInputStream fis = new FileInputStream(fileName);
    File file=new File("decryptedfile.xml");
    if(file.exists()) {
        file.delete();
    }
            FileOutputStream fos = new FileOutputStream("decryptedfile.xml");
    CipherInputStream cis = new CipherInputStream(fis, cipher);
    int i;
    byte[] block = new byte[32];
    //System.out.println("Read : "+cis.read(block));
    while ((i = cis.read(block)) != -1) {
        System.out.println(String.valueOf(i));
        fos.write(block, 0, i);
    }
    fos.close();
}

I just pass in the name of the encrypted file, and the corresponding private key value, into the function. However the cis.read(block) returns -1 on the first attempt. Can anyone suggest how I can decrypt the encrypted file?

  • 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-06T04:24:18+00:00Added an answer on June 6, 2026 at 4:24 am

    Your file is almost certainly not RSA encrypted. Its probably encrypted with AES under a random symmetric key and the key is then encrypted with RSA.

    You are assuming someone actually encrypted the entire file using just RSA. Assuming the implementation even lets you do this (i’ve seen ones that throw exceptions when one tries this), it would be way way way too slow to do anything useful.

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

Sidebar

Related Questions

i'm having a problem while encrypting some data in the file. i'm using simple
I am trying to encrypt some plain text with a public key using RSA_public_encrypt(),
I am having problem transforming xml to xml using xsl. I found out where
I having problem using CHCSVwriter to export my arrays to CSV or excel file.
I am having problem in getting reference of Ajax control extender using $find() or
I'm having problem restricting a query in mdx, using except function at where clause.
I am having problem getting my tooltip to work when using the jQuery load()
I having problem with file download, I am able to download file in emulator
I am having problem in using this font in my Application. I have imported
hi I'm having problem with my database. I'm using access as my database 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.