module Origami::Encryption::EncryptedString
Module for encrypted String
.
Public Class Methods
extended(obj)
click to toggle source
# File lib/origami/encryption.rb, line 393 def self.extended(obj) obj.decrypted = false end
Public Instance Methods
decrypt!()
click to toggle source
# File lib/origami/encryption.rb, line 421 def decrypt! return self if @decrypted cipher = self.document.string_encryption_cipher raise EncryptionError, "Cannot find string encryption filter" if cipher.nil? key = compute_object_key(cipher) self.replace(cipher.decrypt(key, self.to_str)) @decrypted = true self end
encrypt!()
click to toggle source
# File lib/origami/encryption.rb, line 397 def encrypt! return self unless @decrypted cipher = self.document.string_encryption_cipher raise EncryptionError, "Cannot find string encryption filter" if cipher.nil? key = compute_object_key(cipher) encrypted_data = if cipher == RC4 or cipher == Identity cipher.encrypt(key, self.value) else iv = Encryption.rand_bytes(AES::BLOCKSIZE) cipher.encrypt(key, iv, self.value) end @decrypted = false self.replace(encrypted_data) self.freeze self end