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
96
96
Key management:
97
97
* RSA1_5
98
98
* RSA-OAEP (default)
99
- * ~~ RSA-OAEP-256~~
99
+ * RSA-OAEP-256 (if OpenSSL::VERSION >= '3.0')
100
100
* A128KW
101
101
* A192KW
102
102
* A256KW
Original file line number Diff line number Diff line change 5
5
require 'jwe/alg/a256_kw'
6
6
require 'jwe/alg/dir'
7
7
require 'jwe/alg/rsa_oaep'
8
+ require 'jwe/alg/rsa_oaep_256' if OpenSSL ::VERSION >= '3.0'
8
9
require 'jwe/alg/rsa15'
9
10
10
11
module 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 55
55
end
56
56
end
57
57
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 a 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
+
58
81
describe JWE ::Alg ::Rsa15 do
59
82
let ( :alg ) { JWE ::Alg ::Rsa15 . new ( key ) }
60
83
You can’t perform that action at this time.
0 commit comments