Sha256: 8cce7fbbbe7685619126ce438ef360490ef24fd7c165c3775cb427db500dac98

Contents?: true

Size: 1.1 KB

Versions: 20

Compression:

Stored size: 1.1 KB

Contents

module Saml
  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

          Saml::Kit.logger.debug ['-key', @private_key].inspect
          Saml::Kit.logger.debug ['-iv', iv].inspect

          cipher.update(data) + cipher.final
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
saml-kit-0.3.0 lib/saml/kit/crypto/simple_cipher.rb
saml-kit-0.2.18 lib/saml/kit/crypto/simple_cipher.rb
saml-kit-0.2.17 lib/saml/kit/crypto/simple_cipher.rb
saml-kit-0.2.16 lib/saml/kit/crypto/simple_cipher.rb
saml-kit-0.2.15 lib/saml/kit/crypto/simple_cipher.rb
saml-kit-0.2.14 lib/saml/kit/crypto/simple_cipher.rb
saml-kit-0.2.13 lib/saml/kit/crypto/simple_cipher.rb
saml-kit-0.2.12 lib/saml/kit/crypto/simple_cipher.rb
saml-kit-0.2.11 lib/saml/kit/crypto/simple_cipher.rb
saml-kit-0.2.10 lib/saml/kit/crypto/simple_cipher.rb
saml-kit-0.2.9 lib/saml/kit/crypto/simple_cipher.rb
saml-kit-0.2.8 lib/saml/kit/crypto/simple_cipher.rb
saml-kit-0.2.7 lib/saml/kit/crypto/simple_cipher.rb
saml-kit-0.2.6 lib/saml/kit/crypto/simple_cipher.rb
saml-kit-0.2.5 lib/saml/kit/crypto/simple_cipher.rb
saml-kit-0.2.4 lib/saml/kit/crypto/simple_cipher.rb
saml-kit-0.2.3 lib/saml/kit/crypto/simple_cipher.rb
saml-kit-0.2.2 lib/saml/kit/crypto/simple_cipher.rb
saml-kit-0.2.1 lib/saml/kit/crypto/simple_cipher.rb
saml-kit-0.2.0 lib/saml/kit/crypto/simple_cipher.rb