Module: Origami::Encryption::EncryptedStream
- Includes:
- EncryptedObject
- Defined in:
- lib/origami/encryption.rb
Overview
Module for encrypted Stream.
Instance Attribute Summary
Attributes included from EncryptedObject
#algorithm, #decrypted, #encryption_handler, #encryption_key
Instance Method Summary collapse
Methods included from EncryptedObject
Instance Method Details
#decrypt! ⇒ Object
500 501 502 503 504 505 506 507 508 509 |
# File 'lib/origami/encryption.rb', line 500 def decrypt! unless @decrypted key = compute_object_key self.rawdata = @algorithm.decrypt(key, @rawdata) @decrypted = true end self end |
#encrypt! ⇒ Object
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 |
# File 'lib/origami/encryption.rb', line 477 def encrypt! if @decrypted encode! key = compute_object_key @rawdata = if @algorithm == ARC4 or @algorithm == Identity @algorithm.encrypt(key, self.rawdata) else iv = ::Array.new(AES::BLOCKSIZE) { rand(256) }.pack('C*') @algorithm.encrypt(key, iv, @rawdata) end @decrypted = false @rawdata.freeze self.freeze end self end |