c# - Q about AES (CBC) and IV (Is it possible to continue with aes(CBC) encryption? ,... ) -


i'm relatively new c# , encryption, please bear me. i'm writing data file , wanted encrypt using aes (cbc), i'll new data each day , wanted write data 1 file per week, month, year, depends on content. "server" restarted / shut down (it's not going real server) , wanted know if possible somehow (and save file) latest initialization vector after restart continue encrypting data , writing same file. when decrypt file somewhere iv of file , decrypt 1 iv?

pseudocode:

encryption:

1.) encrypting data according iv , key

2.) after data flow stops "special iv" saved 1 other file

3.) data flow stops, time passes, "server" shut down or restarted

4.) read "special iv" file , continue encryption 3. , 4. loop week, month, year

decryption:

1.) read (somehow obtain) iv , key file

2.) decrypt file iv , key

decryption should not notice encryption ever stopped , application exited, ... i've got no idea how realize this, how "special iv". think should possible realize.

what think, there reasonable way obtain special iv? ideas on how it?

thank lot time , answers.

edit: i'm using .net (4.0) implementation of aes , prefer use if possible

to decrypt block in cbc mode, need previous encrypted block: plaintext "aes-decryption of current block xor previous cipher block". encrypt, write multiples of block size file, how cbc works. when start encryption, when start filling file, have pick iv (random, different every file create, make depend on time or such thing), write file first "cipher text block", , every block of actual data, xor previous block file (which in beginning iv), , encrypt block cipher. when new data later, use last block have.

subtle point: write multiples of blocks, you'll need padding. make know how many bytes padding , how many bytes "real data". when start next batch of data, should somehow mark previous block ended "data unit", know that, when decrypting, know blocks need remove padding of actual data. you'll need wrapper around it, or internal structure of data (format) make unambiguous. it's watch out for.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -