Skip to content

Instantly share code, notes, and snippets.

@emerose
Created November 16, 2010 00:37
Show Gist options
  • Select an option

  • Save emerose/701244 to your computer and use it in GitHub Desktop.

Select an option

Save emerose/701244 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# This program encrypts and decrypts messages at the command line.
# It runs setuid root, so that it can be used by users without giving
# them access to the (root-owned) secret encryption key.
require 'openssl'
SECRET_KEY="/etc/secrypt.key"
OUTPUT_FILE="/tmp/secrypt.out"
cipher = OpenSSL::Cipher::Cipher.new('aes-256-ecb')
case ARGV.shift
when 'encrypt'
cipher.encrypt
when 'decrypt'
cipher.decrypt
else
puts "Usage:"
puts "$0 [encrypt|decrypt] "
exit 1
end
cipher.key=(File.read(SECRET_KEY))
input = File.open(ARGV.shift)
output = File.open(OUTPUT_FILE, "w")
input.each_line do |l|
output.write(cipher << l)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment