Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encrypt/Decrypt files using Carrierwave and storing in S3 (Rails)

I need to be able to encrypt files before storing them on S3, and then decrypt them when accessing them. The files will be images, documents, PDF, etc.

I am using Carrierwave to handle the file upload and storage (this is with Ruby on Rails). I am storing them in Amazon S3.

Has anyone done this, or have any ideas how this would be achieved?

Thanks.

like image 975
Joel Friedlaender Avatar asked Sep 01 '11 01:09

Joel Friedlaender


3 Answers

Amazon has now released functionality that lets you encrypt/decrypt files automatically in S3. The need to do this yourself is no longer there. Details are here http://docs.amazonwebservices.com/AmazonS3/latest/dev/index.html?UsingEncryption.html

like image 81
Joel Friedlaender Avatar answered Nov 05 '22 17:11

Joel Friedlaender


To handle the encryption, you should look into implementing a processor. If you are using any other processors, you may have to look at extending the Carrierwave gem and adding a processor ordering mechanism so you can be sure encryption happens last.

For the decryption, you can either override the existing accessor to make the decryption transparent, or add a new method that returns the decrypted file and use that in place of the accessor. The latter approach is probably more resilient to upstream changes.

like image 33
jcnnghm Avatar answered Nov 05 '22 16:11

jcnnghm


I know this post is a few months old, but if you're still looking for answers, check out the carrierwave_securefile gem I wrote. It's still new and probably a bit buggy on other setups, but it uses Crypt19 for Blowfish encryption on files prior to upload.

http://github.com/dougc84/carrierwave_securefile

like image 33
Doug Clark Avatar answered Nov 05 '22 16:11

Doug Clark