Sha256: 06944fb9c848d8447c496fb44f89f0f6cb42fbf119f65b9c1c04e997f1d8f1c9

Contents?: true

Size: 854 Bytes

Versions: 1

Compression:

Stored size: 854 Bytes

Contents

require 'openssl'

# encrypts strings using supplied encryption settings
class Encrypt
  # encrypts a string
  def self.main(settings)
    # setup the encryption parameters
    cipher = OpenSSL::Cipher.new('aes-256-gcm').encrypt
    cipher.key = settings[:key]
    cipher.iv = settings[:nonce]
    cipher.auth_data = settings.key?(:pw) ? settings[:pw] : ''

    # output the encrypted file and associated tag
    if settings[:ui] == :cli
      # output to file
      File.write('encrypted.txt', cipher.update(settings[:file]) + cipher.final)
      File.write('tag.txt', cipher.auth_tag)
      puts 'Your encrypted.txt and associated tag.txt for this encryption have been generated in your current directory.'
    elsif settings[:ui] == :api
      # output to array
      [cipher.update(settings[:file]) + cipher.final, cipher.auth_tag]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rapid-vaults-1.0.0 lib/rapid-vaults/encrypt.rb