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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:22:51+00:00 2026-06-18T07:22:51+00:00

I use AES encryption. It’s ok when I encrypt and then decrypt whole file.

  • 0

I use AES encryption. It’s ok when I encrypt and then decrypt whole file. I want to add multiple files to one encrypted. That’s where the problem is. Encryption is fine, but decryption causes CryptographicException – bad data length. Is it even possible to decrypt part of file or is it encrypted as whole ? I used one cryptostream and passed there all files I want to encrypt to single file. I am trying to do opposite:

AesManaged aes = AES.InitAes(key, salt);
            ICryptoTransform transform = aes.CreateDecryptor(aes.Key, aes.IV);
            int defChunkSize = 1024 * 1024 * 50;

            using (FileStream source = new FileStream(header.data.filename, FileMode.Open))
            {
                foreach (CryptHeader.fileStruct file in header.data.files)
                {
                    preparePath(file.filename);

                    using (FileStream target = new FileStream(file.filename, FileMode.Create))
                    {
                        using (CryptoStream cryptoStream = new CryptoStream(target, transform, CryptoStreamMode.Write))
                        {
                            long padding = source.Length - header.data.files.Sum(x => x.length);//Just test
                            int chunkSize = (defChunkSize > (int)file.length) ? (int)file.length : defChunkSize;
                            byte[] chunkData = new byte[chunkSize];
                            int bytesRead = 0;
                            int totalRead = 0;
                            while (totalRead < file.length)
                            {
                                bytesRead = source.Read(chunkData, 0, chunkSize);
                                if (bytesRead <= 0) break;
                                totalRead += bytesRead;
                                cryptoStream.Write(chunkData, 0, bytesRead);
                            }      
                            chunkData = null;
                        }
                    }
                }
            }    
  • 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-18T07:22:52+00:00Added an answer on June 18, 2026 at 7:22 am

    I’ve done the same few years ago without any problem. The logic I used is the following:

    Encryption

    1. define number of files

    2. define array for keeping encrypted sizes

    3. open output stream

    4. seek (forced) to (number of files * 4) + 4 (assuming lengths are integers)

    5. loop for encryption (encrypt- write encrypted data -assigned encrypted size)

    6. seek to 0 (begin)

    7. write number of files

    8. write encrypted size array

    9. close output stream

    Decryption

    1. open input stream

    2. read number of files

    3. define-read-fill array with encrypted sizes

    4. loop for decryption (read using known sizes)

    5. close output stream

    I hope that this helps.

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

Sidebar

Related Questions

I use AES encryption with the Rijndael class to encrypt passwords and then store
I want to use AES encryption with ISO9797 M2 Padding . But in not
I want to use AES 256bit encryption with Bouncy Castle and I'm wondering if
I want to use AES encryption in my application. I have come across some
In my iOS4+ app i use AES encryption on several places and whole app
Use AES/Rijndael or any symmetric encryption. Encrypt the hidden value using itself as the
Can any one tell me why AES encryption Algorithm is more efficient to use
I want to create a key for use in AES encryption. I found a
I am writing android app that makes AES encryption/decryption of files. I want to
I'm trying to use AES encryption ( AES_ENCRYPT in MySQL) for user passwords but

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.