13aal
13aal

Reputation: 1674

Encrypting files with a decryption key

I'm writing a program that needs to encrypt a log file using openssl and have a decryption key. For example I want to encrypt this file:

This is a test of encrypting a file

This is a test of encrypting a file

Using openssl and I want to be able to decrypt it when I put in some decryption key, for sake of argument 123456789 will be the key.

def decrypt
  print 'Enter key: '
  key = gets.chomp
  if key == decryption_key
    # decrypt file
  else
    # don't decrypt file
  end
end

I've read the docs on openssl but I still don't fully understand how it works, could someone give me an example of what I'm trying to do, along with an example of the decryption part please?

Upvotes: 0

Views: 528

Answers (1)

Kris
Kris

Reputation: 19948

Using aes gem you can do something like:

key = AES.key    
b64 = AES.encrypt("A super secret message", key)
AES.decrypt(b64, key) # => "A super secret message"

Upvotes: 2

Related Questions