RijndaelManaged Encryption: How to store Generated KEY and IV in the Database for later use - REWARD
===

Let me start by saying....yes I have read tons of posts on here in the last two days. No, I don't know anything about encryption, so don't bother...with the you shouldn't playing with fire comments..

I have a asp.net MVC3 application and want to encrypt the photos that users upload using a key for each user.  I want to save this key and use it for any further uploads by the same user and for the decryption. (Although, I suppose I could store a key for each photo instead, not really relevant to this problem but...)

I started with the code from here:
http://www.codeproject.com/Articles/33344/Photo-Video-Viewer-with-Encryption-Capability

It works fine. It encrypts the photos and decrypts them to a new file and all is well.  The "on the fly version" also works and returns a MemoryStream that I can use for my WebImage.  However, as you can see the example is encrypting and decrypting in one pass and the key is a global variable (I don't know what it was, I just used the autogenerated key when I tested.  

So, I need someone to tell me how to store the generated key (and IV I guess???  Told you I know nothing about enc...) in the database for each user and then pull that (those) value(s) back out to use for on the fly decryption. I am not going to bother to post all my code yet, as it is almost identical to what is on the above site.     

I read another post on here and it said to use:
string x = Convert.ToBase64String(RMCrypto.Key);

Then when I wanted to decrypt I used:
RMCrypto.Key = Convert.FromBase64String(x);
 
I stored both the key and IV in this manner in my SQL DB, but when I pull the values and try to decrypt I get an error that the data is not the expected length. 

Maybe I'm totally off base or maybe it's three lines of code....Either way, 
$100 (via PAYPAL) to the first person who actually SOLVES this for me. I don't have time to fool around with this anymore and it's not my area. If you need more information feel free to contact me. 

Thanks!
K
 