File tree Expand file tree Collapse file tree 4 files changed +47
-1
lines changed Expand file tree Collapse file tree 4 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -96,7 +96,7 @@ Only a subset of these algorithms is implemented in this gem. Striked elements a
9696Key management:
9797* RSA1_5
9898* RSA-OAEP (default)
99- * ~~ RSA-OAEP-256~~
99+ * RSA-OAEP-256 (if OpenSSL::VERSION >= '3.0')
100100* A128KW
101101* A192KW
102102* A256KW
Original file line number Diff line number Diff line change 55require 'jwe/alg/a256_kw'
66require 'jwe/alg/dir'
77require 'jwe/alg/rsa_oaep'
8+ require 'jwe/alg/rsa_oaep_256' if OpenSSL ::VERSION >= '3.0'
89require 'jwe/alg/rsa15'
910
1011module JWE
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ module JWE
4+ module Alg
5+ # RSA-OAEP-256 key encryption algorithm.
6+ class RsaOaep256
7+ attr_accessor :key
8+
9+ def initialize ( key )
10+ self . key = key
11+ end
12+
13+ def encrypt ( cek )
14+ key . encrypt ( cek , { rsa_padding_mode : 'oaep' , rsa_oaep_md : 'sha256' } )
15+ end
16+
17+ def decrypt ( encrypted_cek )
18+ key . decrypt ( encrypted_cek , { rsa_padding_mode : 'oaep' , rsa_oaep_md : 'sha256' } )
19+ end
20+ end
21+ end
22+ end
Original file line number Diff line number Diff line change 5555 end
5656end
5757
58+ if OpenSSL ::VERSION >= '3.0'
59+ describe JWE ::Alg ::RsaOaep256 do
60+ let ( :alg ) { JWE ::Alg ::RsaOaep256 . new ( key ) }
61+
62+ describe '#encrypt' do
63+ it 'returns an encrypted string' do
64+ expect ( alg . encrypt ( 'random key' ) ) . to_not eq 'random key'
65+ end
66+ end
67+
68+ it 'decrypts the encrypted key to the original key' do
69+ ciphertext = alg . encrypt ( 'random key' )
70+ expect ( alg . decrypt ( ciphertext ) ) . to eq 'random key'
71+ end
72+ end
73+ else
74+ describe JWE ::Alg do
75+ it 'raises an error for rsa-oaep-256 if openssl < 3.0' do
76+ expect { JWE ::Alg . for ( 'rsa-oaep-256' ) } . to raise_error ( JWE ::NotImplementedError )
77+ end
78+ end
79+ end
80+
5881describe JWE ::Alg ::Rsa15 do
5982 let ( :alg ) { JWE ::Alg ::Rsa15 . new ( key ) }
6083
You can’t perform that action at this time.
0 commit comments