Module: Eon

Defined in:
lib/eon.rb,
lib/eon/eon.rb,
lib/eon/version.rb

Defined Under Namespace

Classes: CLI

Constant Summary collapse

VERSION =
"0.2.0"

Class Method Summary collapse

Class Method Details

.decrypt_file(target, destination) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/eon.rb', line 22

def self.decrypt_file(target, destination)
  encoded_key = IO.read("eon_aes.key")
  cipher = OpenSSL::Cipher.new("aes-256-cbc")
  cipher.decrypt
  cipher.key = Base64.decode64(encoded_key)
  data = IO.read(target)
  data = Base64.decode64(data)
  decrypted = cipher.update(data)
  decrypted << cipher.final
  IO.write(destination, decrypted)
  puts "Successfully decrypted #{target} here: #{destination}"
rescue StandardError
  puts "Error encountered"
end

.encrypt_file(target, destination) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/eon.rb', line 8

def self.encrypt_file(target, destination)
  encoded_key = IO.read("eon_aes.key")
  cipher = OpenSSL::Cipher.new("aes-256-cbc")
  cipher.encrypt
  cipher.key = Base64.decode64(encoded_key)
  data = IO.read(target)
  encrypted = cipher.update(data)
  encrypted << cipher.final
  IO.write(destination, Base64.encode64(encrypted))
  puts "Successfully encrypted #{target} here: #{destination}"
rescue StandardError
  puts "Error encountered"
end

.generateObject



37
38
39
40
41
42
43
# File 'lib/eon.rb', line 37

def self.generate
  cypher = OpenSSL::Cipher.new("aes-256-cbc")
  cypher.encrypt
  key = Base64.encode64(cypher.random_key)
  IO.write("eon_aes.key", key)
  puts "Success"
end