Class: Xmlenc::EncryptedData
- Inherits:
-
Object
- Object
- Xmlenc::EncryptedData
- 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], 'http://www.w3.org/2009/xmlenc11#aes128-gcm' => Algorithms::AESGCM[128], 'http://www.w3.org/2009/xmlenc11#aes192-gcm' => Algorithms::AESGCM[192], 'http://www.w3.org/2009/xmlenc11#aes256-gcm' => Algorithms::AESGCM[256] }
- TYPES =
{ 'http://www.w3.org/2001/04/xmlenc#Element' => :element, 'http://www.w3.org/2001/04/xmlenc#Content' => :content, }
Instance Attribute Summary collapse
-
#node ⇒ Object
Returns the value of attribute node.
Instance Method Summary collapse
- #cipher_value ⇒ Object
- #cipher_value=(value) ⇒ Object
- #decrypt(key) ⇒ Object
- #document ⇒ Object
- #encrypt(data) ⇒ Object
- #encryption_method ⇒ Object
-
#initialize(node) ⇒ EncryptedData
constructor
A new instance of EncryptedData.
- #type ⇒ Object
Constructor Details
#initialize(node) ⇒ EncryptedData
Returns a new instance of EncryptedData.
19 20 21 |
# File 'lib/xmlenc/encrypted_data.rb', line 19 def initialize(node) @node = node end |
Instance Attribute Details
#node ⇒ Object
Returns the value of attribute node.
17 18 19 |
# File 'lib/xmlenc/encrypted_data.rb', line 17 def node @node end |
Instance Method Details
#cipher_value ⇒ Object
31 32 33 |
# 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) ⇒ Object
35 36 37 |
# File 'lib/xmlenc/encrypted_data.rb', line 35 def cipher_value=(value) at_xpath('./xenc:CipherData/xenc:CipherValue').content = value end |
#decrypt(key) ⇒ Object
39 40 41 42 43 44 |
# 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 ⇒ Object
23 24 25 |
# File 'lib/xmlenc/encrypted_data.rb', line 23 def document @node.document end |
#encrypt(data) ⇒ Object
46 47 48 49 50 51 |
# 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 ⇒ Object
27 28 29 |
# File 'lib/xmlenc/encrypted_data.rb', line 27 def encryption_method at_xpath('./xenc:EncryptionMethod') end |
#type ⇒ Object
53 54 55 |
# File 'lib/xmlenc/encrypted_data.rb', line 53 def type TYPES[@node['Type']] end |