Sha256: 978792f0bc637aed4ec7c7af2163428b1e9c1517bcfeda29141cb47851743430
Contents?: true
Size: 1.63 KB
Versions: 3
Compression:
Stored size: 1.63 KB
Contents
module Xmlenc class EncryptedData ALGORITHMS = { 'http://www.w3.org/2001/04/xmlenc#tripledes-cbc' => Algorithms::DES3CBC, 'http://www.w3.org/2001/04/xmlenc#aes128-cbc' => Algorithms::AESCBC[128], 'http://www.w3.org/2001/04/xmlenc#aes256-cbc' => Algorithms::AESCBC[256] } TYPES = { 'http://www.w3.org/2001/04/xmlenc#Element' => :element, 'http://www.w3.org/2001/04/xmlenc#Content' => :content, } attr_accessor :node def initialize(node) @node = node end def document @node.document end def encryption_method at_xpath('./xenc:EncryptionMethod') end def cipher_value at_xpath('./xenc:CipherData/xenc:CipherValue').content.gsub(/[\n\s]/, '') end def cipher_value=(value) at_xpath('./xenc:CipherData/xenc:CipherValue').content = value end def decrypt(key) decryptor = algorithm.setup(key) decrypted = decryptor.decrypt(Base64.decode64(cipher_value), :node => encryption_method) @node.replace(decrypted) unless @node == document.root decrypted end def encrypt(data) encryptor = algorithm.setup encrypted = encryptor.encrypt(data, :node => encryption_method) self.cipher_value = Base64.encode64(encrypted) encryptor.key end def type TYPES[@node['Type']] end private def at_xpath(xpath) @node.at_xpath(xpath, NAMESPACES) end def algorithm algorithm = encryption_method['Algorithm'] ALGORITHMS[algorithm] || raise(UnsupportedError.new("Unsupported encryption method #{algorithm}")) end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
xmlenc-0.2.0 | lib/xmlenc/encrypted_data.rb |
xmlenc-0.1.7 | lib/xmlenc/encrypted_data.rb |
xmlenc-0.1.6 | lib/xmlenc/encrypted_data.rb |