Sha256: f91fc1e4ab18068fc4252c17319e4ca58f654361b801ad122d8239c2b0d27876

Contents?: true

Size: 781 Bytes

Versions: 3

Compression:

Stored size: 781 Bytes

Contents

# frozen_string_literal: true

module Xml
  module Kit
    module Crypto
      class OaepCipher
        ALGORITHM = "#{::Xml::Kit::Namespaces::XMLENC}rsa-oaep-mgf1p"
        ALGORITHMS = {
          ALGORITHM => true
        }.freeze
        attr_reader :algorithm, :key

        def initialize(algorithm, key)
          @algorithm = algorithm
          @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

3 entries across 3 versions & 1 rubygems

Version Path
xml-kit-0.6.0 lib/xml/kit/crypto/oaep_cipher.rb
xml-kit-0.5.0 lib/xml/kit/crypto/oaep_cipher.rb
xml-kit-0.4.0 lib/xml/kit/crypto/oaep_cipher.rb