lib/xml/kit/decryption.rb in xml-kit-0.1.0 vs lib/xml/kit/decryption.rb in xml-kit-0.1.1
- old
+ new
@@ -11,11 +11,26 @@
# Decrypts an EncryptedData section of an XML document.
#
# @param data [Hash] the XML document converted to a [Hash] using Hash.from_xml.
def decrypt(data)
- encrypted_data = data['EncryptedData']
+ ::Xml::Kit.deprecate("decrypt is deprecated. Use decrypt_xml or decrypt_hash instead.")
+ decrypt_hash(data)
+ end
+
+ # Decrypts an EncryptedData section of an XML document.
+ #
+ # @param raw_xml [String] the XML document as a string.
+ def decrypt_xml(raw_xml)
+ decrypt_hash(Hash.from_xml(raw_xml))
+ end
+
+ # Decrypts an EncryptedData section of an XML document.
+ #
+ # @param data [Hash] the XML document converted to a [Hash] using Hash.from_xml.
+ 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
@@ -35,10 +50,10 @@
end
end
end
def to_plaintext(cipher_text, symmetric_key, algorithm)
- Crypto.decryptor_for(algorithm, symmetric_key).decrypt(cipher_text)
+ Crypto.cipher_for(algorithm, symmetric_key).decrypt(cipher_text)
end
end
end
end