Sha256: 802d719ef9f758557da1aac7c691fbb6123c217541e1df8833757c7c9cd3da8a

Contents?: true

Size: 811 Bytes

Versions: 17

Compression:

Stored size: 811 Bytes

Contents

module Xmlenc
  module Algorithms
    class RsaOaepMgf1p
      DIGEST_METHODS = %w(http://www.w3.org/2000/09/xmldsig#sha1)

      def initialize(key)
        @key = key
      end

      def decrypt(cipher_value, options = {})
        verify_algorithm(options[:node]) if options[:node]
        @key.private_decrypt(cipher_value, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
      end

      def encrypt(data)
        @key.public_encrypt(data, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING)
      end

      private

      def verify_algorithm(node)
        digest_method = node.at_xpath('./ds:DigestMethod', NAMESPACES)['Algorithm']
        unless DIGEST_METHODS.include? digest_method
          raise UnsupportedError.new("RSA OEAP MGF1P unsupported digest method #{digest_method}")
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
xmlenc-0.6.3 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.6.2 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.6.1 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.6.0 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.5.0 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.4.1 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.4.0 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.3.0 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.2.1 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.2.0 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.1.7 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.1.6 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.1.5 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.1.4 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.1.3 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.1.2 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.1.1 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb