Class: CcipherBox::EncryptionEngine
- Inherits:
-
Object
- Object
- CcipherBox::EncryptionEngine
- Includes:
- TR::CondUtils
- Defined in:
- lib/ccipher_box/encryption_engine.rb
Overview
Meant to encrypt large data
Instance Method Summary collapse
- #final(&block) ⇒ Object
- #init(output) ⇒ Object
-
#initialize(*args) ⇒ EncryptionEngine
constructor
A new instance of EncryptionEngine.
- #logger ⇒ Object
- #update(data) ⇒ Object
Constructor Details
#initialize(*args) ⇒ EncryptionEngine
Returns a new instance of EncryptionEngine.
11 12 13 |
# File 'lib/ccipher_box/encryption_engine.rb', line 11 def initialize(*args) @keys = args end |
Instance Method Details
#final(&block) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ccipher_box/encryption_engine.rb', line 39 def final(&block) header = @cipher.encrypt_final st = BinStruct.instance.struct(:ccipherbox_cipher) st.keyConfig = @sk.encoded encBaseMat = [] @keys.each do |k| #logger.debug "Encrypt with key #{k.name}" encBaseMat << k.encrypt(@baseMat) end st.baseMaterial = encBaseMat st.cipherConfig = header aheader = st.encoded @output.write(aheader) @intOut.rewind while not @intOut.eof? @output.write(@intOut.read) end @intOut.close @intOut.delete aheader end |
#init(output) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ccipher_box/encryption_engine.rb', line 15 def init(output) raise CcipherBox::Error, "Output is mandatory" if output.nil? @output = output @baseMat = SecureRandom.random_bytes(256/8) @sk = CcipherFactory::SymKeyGenerator.derive(:aes, 256) do |ops| case ops when :password @baseMat end end @intOut = Tempfile.new @cipher = CcipherFactory::SymKeyCipher.encryptor @cipher.output(@intOut) @cipher.key = @sk @cipher.encrypt_init end |
#logger ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/ccipher_box/encryption_engine.rb', line 68 def logger if @logger.nil? @logger = TeLogger::Tlogger.new @logger.tag = :enc_eng end @logger end |
#update(data) ⇒ Object
35 36 37 |
# File 'lib/ccipher_box/encryption_engine.rb', line 35 def update(data) @cipher.encrypt_update(data) end |