3

I have a .net web application, using C#, which will allow users to upload a file, we need to encrypt that file to be more secure, rather than leaving the file as is on the server, so will also need a way to decrypt the file so users can view it from the web application. can someone recommend a way to do this? The files types may vary, but for now they only want .pdf files to by uploaded, if that matters.

Thank you.

Paritosh
  • 4,243
  • 7
  • 47
  • 80
  • **Secure against what/who?** http://blogs.msdn.com/b/ericlippert/archive/2011/09/27/keep-it-secret-keep-it-safe.aspx If you store the key on the same machine, you won't be adding any security. – SLaks Dec 03 '12 at 15:31
  • 1
    Why not just use HTTPS ? – Kek Dec 03 '12 at 15:31
  • is this via http? Just use SSL (e.g. https). – Marc B Dec 03 '12 at 15:31
  • @Kek The problem is not encryption on the transport layer, but rather encryption at rest. For instance, AWS has SSL but no encryption at files at rest. – Candide Dec 03 '12 at 15:38
  • I need to make sure the files are safe at rest, in case someone gets into the box. if i transfer the file to the db, we need to have it go through a WCF service, it's a user requirement for anything that touches the database, so i need to make sure the transfer is secure. i could use SSL for that but i wasn't sure if user would want that, so for now we were planning to leave it on the file system, but not sure how to secure it. – Paritosh Dec 03 '12 at 15:41

1 Answers1

3

Follow the following steps:

  1. Use AES encryption
  2. Generate and store AES keys and IVs as varbinary in the database
  3. Encrypt the file stream that comes when someone uploads a file
  4. Add a general handler *.ashx and, in it, query the database to get the AES keys and IVs
  5. Write to the response stream the decrypted bytes
Community
  • 1
  • 1
Candide
  • 30,469
  • 8
  • 53
  • 60
  • You should encrypt the AES keys before storing them in the db. Don't store the IVs in the db, generate new ones for each file you encrypt and stick them on the front of the encrypted payload, they're a fixed length so you can take them off again for decryption. – BenCr Dec 03 '12 at 15:47
  • 1
    It's not really about storing them in the DB, it's if you use the same key and IV and your clear data starts with the same thing for example `` then each cypher-text will start the same. It just gives away something about what's encrypted, you don't get that with a new IV for each thing encrypted. – BenCr Dec 03 '12 at 15:55