views:

44

answers:

1

In my situation I have a number of files that will be stored on a server. Each of these files is created by a C# application that I am writing.

background: For this application, the amount of time needed to encrypt isnt important, the files tend to be small and we've got plenty of CPU cycles to spare (the client is the only computer that encrypts or decrypts the data).

Each file is unrelated and I need the content to be protected from snooping by the sysadmin or anyone who gets a hold of the hard disk (assume a bad guy)

my understanding is RijndaelAlg is a solid algorithm for this sort of operation? assuming this is information is correct how to I correctly use the RijndaelAlg.CreateEncryptor function?

the usability I want is for my user to type in a password, assume the password is a good password.

my questions are

  1. how best to convert a user inputed string (C# 'string) into a byte[]? I'm assuming I should hash to get around the problem of having 0's on every other character? what is the best way to do this conversion?

  2. what do I use for the IV? it's my understanding this is a value that should be populated (even though MSDN says its okay to pass 'null'). what do I use for this value? keep in mind for my situation I've got a bunch of independent files that need to be decrypted independently.

    what if the IV is well known, is this a problem? (could i use a hash of the filename since it's a unique value)

  3. is there a better algorithm than RijndaelAlg for encrypting many independent files using the same password?

+2  A: 

Q1. I usually use the GetBytes() method of the UTF8 class to convert strings to byte arrays.

Encoding.UTF8.GetBytes(myString)

Q2. Each time you create an instance of the RijndaelManaged class, an IV is randomly generated for you (accessible using the IV property). You can randomize this again by calling the GenerateIV() method.

As you need this IV to decrypt data, you may be better off storing this IV somewhere instead of having a unique IV per file. If you encrypt all your files using a static IV, make sure to set the IV when you're creating a new instance of the RijndaelManaged class any time you decrypt a file.

Q3. RijndaelManaged/AES is the most secure algorithm out there, I wouldn't use anything els.

Damien Dennehy
Don't attempt to encode the string, use PasswordDeriveBytes or Rfc2898DeriveBytes.
GregS
Hmm, good point as I forgot that it's for encrypting a password.
Damien Dennehy