Class: Xml::Kit::Decryption

Inherits:
Object
  • Object
show all
Defined in:
lib/xml/kit/decryption.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(private_keys:) ⇒ Decryption

Returns a new instance of Decryption.



8
9
10
# File 'lib/xml/kit/decryption.rb', line 8

def initialize(private_keys:)
  @private_keys = private_keys
end

Instance Attribute Details

#private_keys ⇒ Object (readonly)

The list of private keys to use to attempt to decrypt the document.



6
7
8
# File 'lib/xml/kit/decryption.rb', line 6

def private_keys
  @private_keys
end

Instance Method Details

#decrypt(data) ⇒ Object

Decrypts an EncryptedData section of an XML document.

Parameters:

  • data (Hash) —

    the XML document converted to a [Hash] using Hash.from_xml.



15
16
17
18
# File 'lib/xml/kit/decryption.rb', line 15

def decrypt(data)
  ::Xml::Kit.deprecate("decrypt is deprecated. Use decrypt_xml or decrypt_hash instead.")
  decrypt_hash(data)
end

#decrypt_hash(hash) ⇒ Object

Decrypts an EncryptedData section of an XML document.

Parameters:

  • data (Hash) —

    the XML document converted to a [Hash] using Hash.from_xml.



30
31
32
33
34
35
# File 'lib/xml/kit/decryption.rb', line 30

def decrypt_hash(hash)
  encrypted_data = hash['EncryptedData']
  symmetric_key = symmetric_key_from(encrypted_data)
  cipher_text = Base64.decode64(encrypted_data["CipherData"]["CipherValue"])
  to_plaintext(cipher_text, symmetric_key, encrypted_data["EncryptionMethod"]['Algorithm'])
end

#decrypt_xml(raw_xml) ⇒ Object

Decrypts an EncryptedData section of an XML document.

Parameters:

  • raw_xml (String) —

    the XML document as a string.



23
24
25
# File 'lib/xml/kit/decryption.rb', line 23

def decrypt_xml(raw_xml)
  decrypt_hash(Hash.from_xml(raw_xml))
end