Module: Origami::Encryption::EncryptedString

Includes:
EncryptedObject
Defined in:
lib/origami/encryption.rb

Overview

Module for encrypted String.

Instance Attribute Summary

Attributes included from EncryptedObject

#algorithm, #decrypted, #encryption_handler, #encryption_key

Instance Method Summary collapse

Methods included from EncryptedObject

extended, #post_build

Instance Method Details

#decrypt!Object



460
461
462
463
464
465
466
467
468
# File 'lib/origami/encryption.rb', line 460

def decrypt!
  unless @decrypted
    key = compute_object_key
    self.replace(@algorithm.decrypt(key, self.to_str))
    @decrypted = true
  end

  self
end

#encrypt!Object



439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/origami/encryption.rb', line 439

def encrypt!
  if @decrypted
    key = compute_object_key
    
    encrypted_data = 
    if @algorithm == ARC4 or @algorithm == Identity
      @algorithm.encrypt(key, self.value)
    else
      iv = ::Array.new(AES::BLOCKSIZE) { rand(256) }.pack('C*')
      @algorithm.encrypt(key, iv, self.value)
    end

    @decrypted = false

    self.replace(encrypted_data)
    self.freeze
  end
  
  self
end