Commit d979cc3
Changed files (2)
lib
xml
kit
crypto
spec
xml
kit
crypto
lib/xml/kit/crypto/symmetric_cipher.rb
@@ -31,9 +31,10 @@ module Xml
end
def decrypt(cipher_text)
+ bytes = cipher_text.bytes
result = default_decrypt(
- cipher_text[0...cipher.iv_len],
- cipher_text[cipher.iv_len..-1]
+ bytes[0...cipher.iv_len],
+ bytes[cipher.iv_len..-1]
)
return result if padding.nil?
@@ -51,8 +52,8 @@ module Xml
cipher.decrypt
cipher.padding = padding unless padding.nil?
cipher.key = @key
- cipher.iv = initialization_vector
- cipher.update(data) << cipher.final
+ cipher.iv = initialization_vector.pack('c*')
+ cipher.update(data.pack('c*')) << cipher.final
end
private
spec/xml/kit/crypto/symmetric_cipher_spec.rb
@@ -30,7 +30,7 @@ RSpec.describe ::Xml::Kit::Crypto::SymmetricCipher do
let(:secret) { SecureRandom.hex }
let(:data) { "#{iv}#{secret}".strip }
- context "when encoded as ASCII" do
+ context 'when encoded as ASCII' do
before do
IO.write(original_file, data, encoding: Encoding::ASCII_8BIT)
execute_shell([
@@ -48,7 +48,7 @@ RSpec.describe ::Xml::Kit::Crypto::SymmetricCipher do
end
end
- context "when encoded as UTF-8" do
+ context 'when encoded as UTF-8' do
before do
IO.write(original_file, data)
execute_shell([