Module: Dgen::OutputFile
- Defined in:
- lib/dgen/outputfile.rb
Overview
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.
Class Method Summary collapse
-
.decrypt(file, key) ⇒ Object
Decrypts a blowfish encrypted file.
-
.encrypt(file, key) ⇒ Object
Encrypts a plaintext file using blowfish encryption.
-
.open_ofile(file, key) ⇒ Object
Opens a previously saved output file for reading.
-
.save_batch(o_file, key, phrases) ⇒ Object
Saves passphrases to a file.
-
.save_pass(o_file, key, phrase) ⇒ Object
Saves passphrase to a file.
Class Method Details
.decrypt(file, key) ⇒ Object
Decrypts a blowfish encrypted file.
42 43 44 45 |
# 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) ⇒ Object
Encrypts a plaintext file using blowfish encryption.
34 35 36 37 38 |
# 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) ⇒ Object
Opens a previously saved output file for reading.
69 70 71 72 73 74 75 |
# 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) ⇒ Object
Saves passphrases to a file.
58 59 60 61 62 63 64 65 |
# 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) ⇒ Object
Saves passphrase to a file.
49 50 51 52 53 54 |
# 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 |