Class: CarrierWave::SecureFile::AESFileDecrypt

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) ⇒ AESFileDecrypt

Returns a new instance of AESFileDecrypt.



111
112
113
114
115
116
117
# File 'lib/carrierwave/securefile/aes_file.rb', line 111

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

Instance Method Details

#do(from_file, to_file) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/carrierwave/securefile/aes_file.rb', line 119

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