main
1# frozen_string_literal: true
2
3module Xml
4 module Kit
5 module Crypto
6 class OaepCipher
7 ALGORITHM = "#{::Xml::Kit::Namespaces::XMLENC}rsa-oaep-mgf1p"
8 ALGORITHMS = {
9 ALGORITHM => true
10 }.freeze
11 attr_reader :algorithm, :key
12
13 def initialize(algorithm, key)
14 @algorithm = algorithm
15 @key = key
16 end
17
18 def self.matches?(algorithm)
19 ALGORITHMS[algorithm]
20 end
21
22 def encrypt(plain_text)
23 @key.public_encrypt(plain_text, padding)
24 end
25
26 def decrypt(cipher_text)
27 @key.private_decrypt(cipher_text, padding)
28 end
29
30 private
31
32 def padding
33 OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING
34 end
35 end
36 end
37 end
38end