Sha256: 339079510b2dc12aa4ab941990bb77a156ac1006d65a668c6c8a60de9ef1e4b0

Contents?: true

Size: 1005 Bytes

Versions: 1

Compression:

Stored size: 1005 Bytes

Contents

module Xml
  module Kit
    module Crypto
      class SimpleCipher
        ALGORITHMS = {
          'http://www.w3.org/2001/04/xmlenc#tripledes-cbc' => 'DES-EDE3-CBC',
          'http://www.w3.org/2001/04/xmlenc#aes128-cbc' => 'AES-128-CBC',
          'http://www.w3.org/2001/04/xmlenc#aes192-cbc' => 'AES-192-CBC',
          'http://www.w3.org/2001/04/xmlenc#aes256-cbc' => 'AES-256-CBC',
        }

        def initialize(algorithm, private_key)
          @algorithm = algorithm
          @private_key = private_key
        end

        def self.matches?(algorithm)
          ALGORITHMS[algorithm]
        end

        def decrypt(cipher_text)
          cipher = OpenSSL::Cipher.new(ALGORITHMS[@algorithm])
          cipher.decrypt
          iv = cipher_text[0..cipher.iv_len-1]
          data = cipher_text[cipher.iv_len..-1]
          #cipher.padding = 0
          cipher.key = @private_key
          cipher.iv = iv
          cipher.update(data) + cipher.final
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
xml-kit-0.1.0 lib/xml/kit/crypto/simple_cipher.rb