Created
November 16, 2010 00:37
-
-
Save emerose/701244 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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