Class: CarrierWave::SecureFile::AESFileEncrypt

Inherits:
Object
  • Object
show all
Includes:
AESFile
Defined in:
lib/carrierwave/securefile/aes_file.rb

Instance Attribute Summary

Attributes included from AESFile

#cipher, #cipher_type, #iv, #key

Instance Method Summary collapse

Methods included from AESFile

#init_cipher, #set_cipher_iv, #set_cipher_key, #set_cipher_method

Constructor Details

#initialize(key, iv) ⇒ AESFileEncrypt

Returns a new instance of AESFileEncrypt.



84
85
86
87
88
89
90
# File 'lib/carrierwave/securefile/aes_file.rb', line 84

def initialize(key, iv)
  self.cipher_type = 'aes-256-cbc'
  init_cipher self.cipher_type
  set_cipher_method :encrypt
  set_cipher_key key
  set_cipher_iv iv
end

Instance Method Details

#do(from_file, to_file) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/carrierwave/securefile/aes_file.rb', line 92

def do(from_file, to_file)

  buf = ""
  File.open(to_file, "wb") do |outf|
    File.open(from_file, "rb") do |inf|
      while inf.read(4096, buf)
        outf << self.cipher.update(buf)
      end
      outf << self.cipher.final
    end
  end
end