Encrypting/Decrypting files wirh ruby.

Discussion in 'Ruby' started by Demetris Constantinou, Apr 30, 2010.

  1. I have been searching the internet to find a way to encrypt files and
    then decrypt the back.. What I found is how to encrypt a string of text
    and then decrypt it back.

    For exampe you have a
    plaintext = "some text"

    you encrypt it into a ciphertext and then how to decrypt it back.

    What I want to do is to encrypt a whole file, files like .doc, .docx,
    xls, .pps and so on. Basically any file either this is a document, a
    photo or whatever.

    Any help on how to achieve this. I found a library 'ChilKat' but you
    need to purchase a license to do this.

    Any help is much appreciated!

    Regards,
    Demetris Constantinou
    --
    Posted via http://www.ruby-forum.com/.
    Demetris Constantinou, Apr 30, 2010
    #1
    1. Advertising

  2. Demetris Constantinou

    Baduk Baduk Guest

    There are many examples of using OpenSSL to encrypt and decrypt files in
    Ruby, which can be found via Google.

    But why not just use OpenSSL straight from the command line?

    Demetris Constantinou wrote:
    > I have been searching the internet to find a way to encrypt files and
    > then decrypt the back.. What I found is how to encrypt a string of text
    > and then decrypt it back.
    >
    > For exampe you have a
    > plaintext = "some text"
    >
    > you encrypt it into a ciphertext and then how to decrypt it back.
    >
    > What I want to do is to encrypt a whole file, files like .doc, .docx,
    > .xls, .pps and so on. Basically any file either this is a document, a
    > photo or whatever.
    >
    > Any help on how to achieve this. I found a library 'ChilKat' but you
    > need to purchase a license to do this.
    >
    > Any help is much appreciated!
    >
    > Regards,
    > Demetris Constantinou


    --
    Posted via http://www.ruby-forum.com/.
    Baduk Baduk, May 1, 2010
    #2
    1. Advertising

  3. Baduk thanx for your reply.

    I want to use it in a Rails application to encrypt the files and then
    store them!


    Baduk Baduk wrote:
    > There are many examples of using OpenSSL to encrypt and decrypt files in
    > Ruby, which can be found via Google.
    >
    > But why not just use OpenSSL straight from the command line?
    >
    > Demetris Constantinou wrote:
    >> I have been searching the internet to find a way to encrypt files and
    >> then decrypt the back.. What I found is how to encrypt a string of text
    >> and then decrypt it back.
    >>
    >> For exampe you have a
    >> plaintext = "some text"
    >>
    >> you encrypt it into a ciphertext and then how to decrypt it back.
    >>
    >> What I want to do is to encrypt a whole file, files like .doc, .docx,
    >> .xls, .pps and so on. Basically any file either this is a document, a
    >> photo or whatever.
    >>
    >> Any help on how to achieve this. I found a library 'ChilKat' but you
    >> need to purchase a license to do this.
    >>
    >> Any help is much appreciated!
    >>
    >> Regards,
    >> Demetris Constantinou


    --
    Posted via http://www.ruby-forum.com/.
    Demetris Constantinou, May 1, 2010
    #3
  4. ruby's openssl library works fine, but it's quite low level, which means
    that if you don't understand much about cryptography it's easy to write
    an insecure application.

    So if you're not an expert I'd suggest using gpg instead. Google "ruby
    gpg" and "ruby gpgme" and you'll find plenty of examples.

    I'd say the main weakness of your application is likely to be the key
    storage. That is, if you keep your encryption keys in a file or in a
    database, then anyone who breaks into your box will be able to decrypt
    these encrypted files anyway, in which case the encryption is fairly
    pointless.

    You could make your app prompt for the key when it starts up and keep it
    only in RAM. This can make it harder for an attacker to extract the key,
    but it can be awkward to deploy in a Rails app if you are dynamically
    starting worker processes.

    Regards,

    Brian.
    --
    Posted via http://www.ruby-forum.com/.
    Brian Candler, May 2, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marshall Dudley

    encrypting and decrypting with perl

    Marshall Dudley, Jan 27, 2005, in forum: Perl
    Replies:
    1
    Views:
    728
    Brian McCauley
    Jan 27, 2005
  2. VB Programmer

    Encrypting/Decrypting Connection String

    VB Programmer, Nov 29, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    7,598
    Sahil Malik
    Nov 30, 2004
  3. Replies:
    35
    Views:
    50,733
    Chris Uppal
    Nov 9, 2005
  4. dfa_geko
    Replies:
    3
    Views:
    377
    dfa_geko
    Apr 6, 2007
  5. Andy Chau
    Replies:
    7
    Views:
    197
    Andy Chau
    Oct 5, 2003
Loading...

Share This Page