Method: CcipherBox::EncryptionEngine#final

Defined in:
lib/ccipher_box/encryption_engine.rb

#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