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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:08:40+00:00 2026-05-15T16:08:40+00:00

I have created a test (not real) encryption function which takes a byte[] and

  • 0

I have created a test (not real) encryption function which takes a byte[] and replaces all the bytes with 0xff and returns

private byte[] encrypt(byte[] input)
        {


            for (int i = 0; i < input.Length; i++)
            {
                input[i] = 0xff;
            }

            return input;



        }

Now i want to try this test encryption procedure on a file. But i want to be able to read and write to the SAME file.

This is what I have done so far

using (FileStream myfileStream = new FileStream(openFile, FileMode.Open,FileAccess.ReadWrite))

    {   

    byte[] buffer = new byte[16]; 



        while (myfileStream.Position < myfileStream.Length)
        {

          myfileStream.Read(buffer, 0, 16);

          buffer = encrypt(buffer);

          myfileStream.Position -= 16;

          myfileStream.Write(buffer, 0, 16);

         }

         myfileStream.Close();            

    }

This works fine but I know I am not doing this right. This seems to have VERY serious performance issues where it took 24 seconds for a 1 MB file. (Tested with a StopWatch in a WinMo 6 Pro emulator).

What am I doing wrong here? What can I do to increase the performance when reading and writing to/from the same file at the same time ? Please advise. Thanx a lot in advance 🙂


UPDATE:

I reduced the time it took significantly (from 24 seconds, down to 6 seconds) by using 2 FileStream objects pointing to the same file with FileShare.ReadWrite property.

Is this safe to do? Is this ok?

UPDATE AGAIN

Although I have used a fake encryption algorithm, I am hoping to use AES with CBC + CTS.

  • 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-15T16:08:41+00:00Added an answer on May 15, 2026 at 4:08 pm

    A couple of things come to mind immediately:

    1. Use a larger buffer – why only 16 bytes?
    2. Don’t write to the same file – you can delete/rename after encrypting.

    Update

    Even with EAS and the 16 byte constraint, you can do the encryption in memory (for large files, use a large buffer instead of encrypting the whole file in memory).

    You should not be using two filesteams like that – you may end up writing parts of the file that you will be reading on later.

    In regards to the buffers – you can read large chunks from disk, then operate on 16 bytes at a time in memory before writing back large chunks of encrypted data.

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

Sidebar

Ask A Question

Stats

  • Questions 494k
  • Answers 494k
  • 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 I bet it's just a really simple error in your… May 16, 2026 at 11:11 am
  • Editorial Team
    Editorial Team added an answer You're on the right track. Check out the NerdDinner sample… May 16, 2026 at 11:11 am
  • Editorial Team
    Editorial Team added an answer You may want to set your switchValue's to All --… May 16, 2026 at 11:11 am

Trending Tags

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

Top Members

Related Questions

I have a listview which I would like to fill with self created user
I have created a debugger visualizer in VS2008. There are two classes i've made,
I have an iPhone app which submits user entered data to a SQL database.
Lots of developers think that testing private methods is a bad idea. However, all
Thank you all for your help. A number of you posted (as I should
I have seen many posts and questions about Mocking a private method but still
I have the following challenge, and I haven't found a good answer. I am
I have a viewController containing the following method: - (IBAction) playMovie { NSURL *url
I am writing my first iPhone App, a test case before I write my
I'm working with a system which had to create objects in one database based

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.