Search code examples
c#encryption-symmetric

Is it necessary to use Initialization Vector at the time of Encryption and Decryption?


I am newbie to C# and I have a task to encrypt the files in C# and put it onto server (Mentioned that use 256-bit AES encryption). Whoever wants it, they should Decrypt it first and then use it.

But I have some doubts related to it as: I am using AESCryptoServiceProvider Class. In that I am using the method CreateEncryptor(Byte[], Byte[]). But the question I want to ask is, If I encrypt the file using key as well as IV, then I have to share the both with the user Key and IV.

What should I do in such case? I want that I should use only key at the time of encryption and decryption. How can I do that?

I am totally confused about it. Please suggest me some steps over it.

Thanks


Solution

  • As far as i know, the IV doesn't need to be secret, so you could store it together with the encrypted data on the server. Just make sure that each IV is random and that you don't reuse them.

    For more details on the IV, look here:
    http://en.wikipedia.org/wiki/Initialization_vector