Sha256: bce0af7e689943627049ba75e636772ed51957af7a9c3768fe4caf38c81b00eb

Contents?: true

Size: 825 Bytes

Versions: 8

Compression:

Stored size: 825 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, options = {})
        @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

8 entries across 8 versions & 1 rubygems

Version Path
xmlenc-0.8.0 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.7.1 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.7.0 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.6.9 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.6.8 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.6.6 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.6.5 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb
xmlenc-0.6.4 lib/xmlenc/algorithms/rsa_oaep_mgf1p.rb