Sha256: 07bb860080067ab438ab15db41afd5db8f117b5c1f78e0f7107d614e113a1269

Contents?: true

Size: 682 Bytes

Versions: 2

Compression:

Stored size: 682 Bytes

Contents

# frozen_string_literal: true

module Xml
  module Kit
    module Crypto
      class OaepCipher
        ALGORITHMS = {
          'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p' => true,
        }.freeze
        def initialize(_algorithm, key)
          @key = key
        end

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

        def encrypt(plain_text)
          @key.public_encrypt(plain_text, padding)
        end

        def decrypt(cipher_text)
          @key.private_decrypt(cipher_text, padding)
        end

        private

        def padding
          OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
xml-kit-0.1.13 lib/xml/kit/crypto/oaep_cipher.rb
xml-kit-0.1.12 lib/xml/kit/crypto/oaep_cipher.rb