Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Encrypt a File *Blowfish* (See related posts)

// A simple ruby script to encrypt a file

#
#   A simple ruby script to encrypt a file
#     can be edited to encrypt directories also
#
#    Written by:  Steve at pentest.it
#                 www.pentest.it
#
#    Using the blowfish algorithm
#        several algorithms exist, just substitute for 'blowfish'
#
require 'crypt/blowfish'

begin
#take in the file name to encrypt as an argument
  filename = ARGV.shift
  puts filename
  c = "Encrypted_#{filename}"
#User specifies a key from 1-56 bytes (Don't forget this or your stuff is history)
  print 'Enter your encryption key (1-56 bytes): '
  kee = gets
#initialize the encryption method using the user input key
  blowfish = Crypt::Blowfish.new(kee)
  blowfish.encrypt_file(filename.to_str, c)
#encrypt the file
  puts 'Encryption SUCCESS!'
rescue
#if the script busts for any reason this will catch it
  puts "\n\n\nSorry the encryption was unsuccessful"
  puts "USAGE: ruby encryption.rb <plaintext file>\n\n\n"
  raise
end

You need to create an account or log in to post comments to this site.


Related Posts