class Sekreti::Core

Main class performing operations.

Protected Class Methods

decrypt!(options) click to toggle source

Decrypts a file with a submitted key. @param options [Hash] submitted parameters @return boolean

# File lib/sekreti/core.rb, line 34
def self.decrypt!(options)
  begin
    decipher = OpenSSL::Cipher.new(options[:protocol])
    decipher.decrypt
    decipher.key =  options[:key]

    f = File.open(options[:output_file], 'w')
    decrypted = decipher.update(File.read(options[:path])) + decipher.final
    f.write(decrypted)

    return true
  rescue
    return false
  end
end
encrypt!(options) click to toggle source

Encrypts a file with AES-128-CBC cipher, using a submitted 16 bytes string. @param options [Hash] submitted parameters @return boolean

# File lib/sekreti/core.rb, line 11
def self.encrypt!(options)
  begin
    cipher = OpenSSL::Cipher.new(options[:protocol])
    cipher.encrypt
    cipher.key = options[:key]

    f = File.open(
      options[:output_file], 
      'wb'
    )
    
    encrypted = cipher.update(File.read(options[:path])) + cipher.final
    f.write(encrypted)

    return true
  rescue
    return false
  end
end