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



482
483
484
485
486
487
488
489
490
# File 'lib/origami/encryption.rb', line 482

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

  self
end

#encrypt!Object



461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
# File 'lib/origami/encryption.rb', line 461

def encrypt!
  if @decrypted
    key = compute_object_key
    
    encrypted_data = 
    if @algorithm == ARC4 or @algorithm == Identity
      @algorithm.encrypt(key, self.value)
    else
      iv = Encryption.rand_bytes(AES::BLOCKSIZE)
      @algorithm.encrypt(key, iv, self.value)
    end

    @decrypted = false

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