Class: Xmlenc::EncryptedData

Inherits:
Object
  • Object
show all
Defined in:
lib/xmlenc/encrypted_data.rb

Constant Summary collapse

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]
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ EncryptedData

Returns a new instance of EncryptedData.



11
12
13
# File 'lib/xmlenc/encrypted_data.rb', line 11

def initialize(node)
  @node = node
end

Instance Attribute Details

#nodeObject

Returns the value of attribute node.



9
10
11
# File 'lib/xmlenc/encrypted_data.rb', line 9

def node
  @node
end

Instance Method Details

#cipher_valueObject



23
24
25
# File 'lib/xmlenc/encrypted_data.rb', line 23

def cipher_value
  at_xpath('./xenc:CipherData/xenc:CipherValue').content.gsub(/[\n\s]/, '')
end

#decrypt(key) ⇒ Object



27
28
29
30
# File 'lib/xmlenc/encrypted_data.rb', line 27

def decrypt(key)
  decryptor = algorithm.setup(key)
  decryptor.decrypt(Base64.decode64(cipher_value), node: encryption_method)
end

#documentObject



15
16
17
# File 'lib/xmlenc/encrypted_data.rb', line 15

def document
  @node.document
end

#encryption_methodObject



19
20
21
# File 'lib/xmlenc/encrypted_data.rb', line 19

def encryption_method
  at_xpath('./xenc:EncryptionMethod')
end