Directly obtaining the key form, your password using Encoding.GetBytes() will work only if the result of GetBytes () is legitimate KeySize.
More importantly, it makes a very weak key, especially since you have chosen Unicode encoding. The byte pattern in your key for "foobar" is 66 00 6F 00 6F 00 62 00 61 00 72 00 . Do you see all 00 bytes?
The official way is to use the Rfc2898DeriveBytes class. Also, it is probably not recommended to use the key as an IV, I'm not quite sure about this.
Also see this SO question .
Henk holterman
source share