@@ -125,6 +125,9 @@ func (e RSA) Decrypt(key interface{}, ciphertextEl *etree.Element) ([]byte, erro
125
125
// the block cipher used is AES-256 CBC and the digest method is SHA-256. You can
126
126
// specify other ciphers and digest methods by assigning to BlockCipher or
127
127
// DigestMethod.
128
+ //
129
+ // OAEP implements the older RSA-OAEP (2001 spec) for backward compatibility, you might
130
+ // perfer OAEP_2009_256 over using this method.
128
131
func OAEP () RSA {
129
132
return RSA {
130
133
BlockCipher : AES256CBC ,
@@ -139,6 +142,44 @@ func OAEP() RSA {
139
142
}
140
143
}
141
144
145
+ // OAEP_SHA256 returns a version of RSA that implements RSA in OAEP mode. By default
146
+ // the block cipher used is AES-256 CBC and the digest method is SHA-256. You can
147
+ // specify other ciphers and digest methods by assigning to BlockCipher or
148
+ // DigestMethod.
149
+ func OAEP_SHA256 () RSA { //nolint:revive
150
+ return RSA {
151
+ BlockCipher : AES256CBC ,
152
+ DigestMethod : SHA256 ,
153
+ algorithm : "http://www.w3.org/2009/xmlenc11#rsa-oaep" ,
154
+
155
+ keyEncrypter : func (e RSA , pubKey * rsa.PublicKey , plaintext []byte ) ([]byte , error ) {
156
+ return rsa .EncryptOAEP (e .DigestMethod .Hash (), RandReader , pubKey , plaintext , nil )
157
+ },
158
+ keyDecrypter : func (e RSA , privKey * rsa.PrivateKey , ciphertext []byte ) ([]byte , error ) {
159
+ return rsa .DecryptOAEP (e .DigestMethod .Hash (), RandReader , privKey , ciphertext , nil )
160
+ },
161
+ }
162
+ }
163
+
164
+ // OAEP_SHA512 returns a version of RSA that implements RSA in OAEP mode. By default
165
+ // the block cipher used is AES-256 CBC and the digest method is SHA-512. You can
166
+ // specify other ciphers and digest methods by assigning to BlockCipher or
167
+ // DigestMethod.
168
+ func OAEP_SHA512 () RSA { //nolint:revive
169
+ return RSA {
170
+ BlockCipher : AES256CBC ,
171
+ DigestMethod : SHA512 ,
172
+ algorithm : "http://www.w3.org/2009/xmlenc11#rsa-oaep" ,
173
+
174
+ keyEncrypter : func (e RSA , pubKey * rsa.PublicKey , plaintext []byte ) ([]byte , error ) {
175
+ return rsa .EncryptOAEP (e .DigestMethod .Hash (), RandReader , pubKey , plaintext , nil )
176
+ },
177
+ keyDecrypter : func (e RSA , privKey * rsa.PrivateKey , ciphertext []byte ) ([]byte , error ) {
178
+ return rsa .DecryptOAEP (e .DigestMethod .Hash (), RandReader , privKey , ciphertext , nil )
179
+ },
180
+ }
181
+ }
182
+
142
183
// PKCS1v15 returns a version of RSA that implements RSA in PKCS1v15 mode. By default
143
184
// the block cipher used is AES-256 CBC. The DigestMethod field is ignored because PKCS1v15
144
185
// does not use a digest function.
0 commit comments