class Xmlenc::EncryptedKey

Constants

ALGORITHMS

Public Class Methods

new(node) click to toggle source
# File lib/xmlenc/encrypted_key.rb, line 8
def initialize(node)
  @node = node
end

Public Instance Methods

cipher_value() click to toggle source
# File lib/xmlenc/encrypted_key.rb, line 24
def cipher_value
  at_xpath('./xenc:CipherData/xenc:CipherValue').content.gsub(/[\n\s]/, '')
end
cipher_value=(value) click to toggle source
# File lib/xmlenc/encrypted_key.rb, line 28
def cipher_value=(value)
  at_xpath('./xenc:CipherData/xenc:CipherValue').content = value
end
decrypt(key) click to toggle source
# File lib/xmlenc/encrypted_key.rb, line 32
def decrypt(key)
  decryptor = algorithm.new(key)
  decryptor.decrypt(Base64.decode64(cipher_value), :node => encryption_method)
end
document() click to toggle source
# File lib/xmlenc/encrypted_key.rb, line 12
def document
  @node.document
end
encrypt(key, data) click to toggle source
# File lib/xmlenc/encrypted_key.rb, line 37
def encrypt(key, data)
  encryptor = algorithm.new(key)
  encrypted = encryptor.encrypt(data, :node => encryption_method)
  self.cipher_value = Base64.encode64(encrypted)
end
encrypted_data() click to toggle source
# File lib/xmlenc/encrypted_key.rb, line 20
def encrypted_data
  EncryptedData.new(referenced_node)
end
encryption_method() click to toggle source
# File lib/xmlenc/encrypted_key.rb, line 16
def encryption_method
  at_xpath('./xenc:EncryptionMethod')
end

Private Instance Methods

algorithm() click to toggle source
# File lib/xmlenc/encrypted_key.rb, line 67
def algorithm
  algorithm = encryption_method['Algorithm']
  ALGORITHMS[algorithm] ||
      raise(UnsupportedError.new("Unsupported encryption method #{algorithm}"))
end
at_xpath(xpath) click to toggle source
# File lib/xmlenc/encrypted_key.rb, line 63
def at_xpath(xpath)
  @node.at_xpath(xpath, NAMESPACES)
end
reference_uri() click to toggle source
# File lib/xmlenc/encrypted_key.rb, line 55
def reference_uri
  if at_xpath('./xenc:ReferenceList/xenc:DataReference')
    at_xpath('./xenc:ReferenceList/xenc:DataReference')['URI'][1..-1]
  else
    nil
  end
end
referenced_node() click to toggle source
# File lib/xmlenc/encrypted_key.rb, line 45
def referenced_node
  if reference_uri
    document.at_xpath("//xenc:EncryptedData[@Id='#{reference_uri}']", NAMESPACES) ||
        raise(Xmlenc::EncryptedDataNotFound.new("Encrypted data not found for: #{reference_uri}"))
  else
    @node.at_xpath('ancestor::xenc:EncryptedData', Xmlenc::NAMESPACES) ||
        raise(Xmlenc::EncryptedDataNotFound.new('Encrypted data not in ancestore element'))
  end
end