module Dgen::OutputFile

OutputFile

Author

Dick Davis

Copyright

Copyright 2015-2018 Dick Davis

License

GNU Public License 3

This module provides the methods that enable saving generated passwords securely to a file.

The encryption algorithm used is Blowfish, developed by Bruce Schneier.

Public Class Methods

decrypt(file, key) click to toggle source

Decrypts a blowfish encrypted file.

# File lib/dgen/outputfile.rb, line 42
def self.decrypt(file, key)
  bf = Crypt::Blowfish.new(key)
  bf.decrypt_file(file.to_s, "decrypted_#{file}")
end
encrypt(file, key) click to toggle source

Encrypts a plaintext file using blowfish encryption.

# File lib/dgen/outputfile.rb, line 34
def self.encrypt(file, key)
  bf = Crypt::Blowfish.new(key)
  bf.encrypt_file("plain_#{file}", file.to_s)
  File.delete("plain_#{file}")
end
open_ofile(file, key) click to toggle source

Opens a previously saved output file for reading.

# File lib/dgen/outputfile.rb, line 69
def self.open_ofile(file, key)
  decrypt(file, key)
  File.foreach("decrypted_#{file}") do |l|
    puts "Decrypted passphrase: '#{l.chomp}'"
  end
  File.delete("decrypted_#{file}")
end
save_batch(o_file, key, phrases) click to toggle source

Saves passphrases to a file.

# File lib/dgen/outputfile.rb, line 58
def self.save_batch(o_file, key, phrases)
  f = File.open("plain_#{o_file}", 'w+')
  phrases.each do |phrase|
    f.write phrase + "\n"
  end
  f.close
  encrypt(o_file, key)
end
save_pass(o_file, key, phrase) click to toggle source

Saves passphrase to a file.

# File lib/dgen/outputfile.rb, line 49
def self.save_pass(o_file, key, phrase)
  f = File.open("plain_#{o_file}", 'w+')
  f.puts phrase
  f.close
  encrypt(o_file, key)
end