class Xmlenc::EncryptedData
Constants
- ALGORITHMS
- TYPES
Attributes
node[RW]
Public Class Methods
new(node)
click to toggle source
# File lib/xmlenc/encrypted_data.rb, line 19 def initialize(node) @node = node end
Public Instance Methods
cipher_value()
click to toggle source
# File lib/xmlenc/encrypted_data.rb, line 31 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_data.rb, line 35 def cipher_value=(value) at_xpath('./xenc:CipherData/xenc:CipherValue').content = value end
decrypt(key)
click to toggle source
# File lib/xmlenc/encrypted_data.rb, line 39 def decrypt(key) decryptor = algorithm.setup(key) decrypted = decryptor.decrypt(Base64.decode64(cipher_value), :node => encryption_method) @node.replace(Nokogiri::XML::DocumentFragment.parse(decrypted)) unless @node == document.root decrypted end
document()
click to toggle source
# File lib/xmlenc/encrypted_data.rb, line 23 def document @node.document end
encrypt(data)
click to toggle source
# File lib/xmlenc/encrypted_data.rb, line 46 def encrypt(data) encryptor = algorithm.setup encrypted = encryptor.encrypt(data, :node => encryption_method) self.cipher_value = Base64.encode64(encrypted) encryptor.key end
encryption_method()
click to toggle source
# File lib/xmlenc/encrypted_data.rb, line 27 def encryption_method at_xpath('./xenc:EncryptionMethod') end
type()
click to toggle source
# File lib/xmlenc/encrypted_data.rb, line 53 def type TYPES[@node['Type']] end
Private Instance Methods
algorithm()
click to toggle source
# File lib/xmlenc/encrypted_data.rb, line 63 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_data.rb, line 59 def at_xpath(xpath) @node.at_xpath(xpath, NAMESPACES) end