Commit 7e5333e
Changed files (3)
lib
xml
kit
crypto
spec
xml
kit
crypto
lib/xml/kit/crypto/symmetric_cipher.rb
@@ -31,10 +31,14 @@ module Xml
end
def decrypt(cipher_text)
- default_decrypt(
+ result = default_decrypt(
cipher_text[0...cipher.iv_len],
cipher_text[cipher.iv_len..-1]
)
+ return result if padding.nil?
+
+ padding_size = result.bytes.last
+ result[0...-padding_size]
end
protected
lib/xml/kit/decryption.rb
@@ -32,11 +32,11 @@ module Xml
# @param hash [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_value = encrypted_data['CipherData']['CipherValue']
- cipher_text = Base64.decode64(cipher_value)
- algorithm = encrypted_data['EncryptionMethod']['Algorithm']
- to_plaintext(cipher_text, symmetric_key, algorithm)
+ to_plaintext(
+ Base64.decode64(encrypted_data['CipherData']['CipherValue']),
+ symmetric_key_from(encrypted_data),
+ encrypted_data['EncryptionMethod']['Algorithm']
+ )
end
# Decrypts an EncryptedData Nokogiri::XML::Element.
spec/xml/kit/crypto/symmetric_cipher_spec.rb
@@ -43,7 +43,7 @@ RSpec.describe ::Xml::Kit::Crypto::SymmetricCipher do
specify do
cipher_text = IO.read(encrypted_file, encoding: Encoding::ASCII_8BIT)
- expect(subject.decrypt(cipher_text)).to include(secret)
+ expect(subject.decrypt(cipher_text)).to eql(secret)
end
end