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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:20:18+00:00 2026-05-20T06:20:18+00:00

I’m relatively new to C# and encryption, so please bear with me. I’m writing

  • 0

I’m relatively new to C# and encryption, so please bear with me. I’m writing some data to a file and I wanted to encrypt it using Aes (CBC), but I’ll get new data each day and I wanted to write all the data to one file per week, month, year, it depends on the content. Thus the “server” will be restarted / shut down definitely (it’s not going to be a real server) and I wanted to know if it is possible to somehow get (and save to a file) the latest initialization vector with which I could after restart continue encrypting data and writing it to the same file. So that when I would decrypt the file I would just somewhere get the iv of the file and could decrypt it just with that one iv?

Pseudocode:

Encryption:

1.) encrypting data according to iv and key

2.) after data flow stops “special iv” is saved to one other file

3.) data flow stops, some time passes, “server” is shut down or restarted

4.) read “special iv” from file and continue with encryption
3. and 4. loop for a week, month, year

Decryption:

1.) read (somehow obtain) iv and key from that file

2.) decrypt the file with that iv and key

Decryption should not notice that encryption was ever stopped and application exited, …
I’ve got no idea how to realize this, how to get that “special iv”. But I think this should be possible to realize.

What do you think, is there a reasonable way to obtain that special iv? Any ideas on how to do it?

Thank you a lot for your time and answers.

EDIT: I’m using .NET (4.0) implementation of AES and I would prefer to use that if possible

  • 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-20T06:20:19+00:00Added an answer on May 20, 2026 at 6:20 am

    To decrypt any block in CBC mode, you only need the previous encrypted block: the plaintext will be “AES-decryption of current block XOR previous cipher block”.
    As you encrypt, you will only write multiples of the block size to file, as this is how CBC works. When you start the encryption, so when you start filling the file, you have to pick an IV (random, different for every file you create, so make it depend on the time or some such thing), you write that to file as the very first “cipher text block”, and then for every block of actual data, you XOR it with the previous block from the file (which in the beginning is the IV), and then encrypt with your block cipher. When you get new data later, we just use the last block that you already have.

    Subtle point: as you only write multiples of blocks, you’ll need padding. Make it so that you know how many bytes are padding and how many bytes are “real data”. When you start with a next batch of data, you should somehow mark that the previous block ended a “data unit”, so that you know that, when decrypting, you know which blocks you need to remove the padding of to get the actual data. So you’ll need some wrapper around it, or the internal structure of the data (format) would always make this unambiguous. It’s something to watch out for.

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

Sidebar

Related Questions

No related questions found

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.