如何使用RSA加密数据,使用SHA-256作为散列函数和MGF1作为掩码生成函数? [英] How to encrypt data using RSA, with SHA-256 as hash function and MGF1 as mask generating function?
问题描述
我正在做一些密码学实验。现在我有接收器的公钥,我想加密一些数据并传递给接收器。
I was doing some experiments with cryptography. Now I have the public key of receiver and i want to encrypt some data and pass to the receiver.
我想使用RSAES-OAEP算法。其中SHA-256作为散列函数,MGF1作为掩码生成函数。
I want to use RSAES-OAEP algorithm. with SHA-256 as hash function and MGF1 as mask generation function.
我想使用openssl。我发现一个函数 RSA_public_encrypt()
使用这个函数我们可以指定填充。其中一个填充选项是
I want do this using openssl. I found a function RSA_public_encrypt()
with this function we can specify the padding. One of the padding option available was
RSA_PKCS1_OAEP_PADDING
PKCS#1 v2.0中定义的EME-OAEP SHA-1,MGF1。
RSA_PKCS1_OAEP_PADDING
EME-OAEP as defined in PKCS #1 v2.0 with SHA-1 , MGF1 .
他们使用sha-1。
they are using sha-1.
我想重新配置函数以使用SHA256作为散列函数和MGF1作为散列函数。
I want to reconfigure the function to use SHA256 as hash function ans MGF1 as hash function. How can I do it ?
推荐答案
OpenSSL使用 PKCS#1 v2.0
,因此 EME-OAEP
的默认值为 SHA-1
和 MGF1
。如果你需要使用 SHA-256
,你需要自己做编码。这不是很难,但请参阅 PKCS#1 v2.2 PDF 第18页。
OpenSSL uses definitions from PKCS #1 v2.0
and so the default for EME-OAEP
is SHA-1
and MGF1
. If you need to use SHA-256
, you'll need to do the encoding yourself. This isn't terribly difficult however, see PKCS #1 v2.2 PDF Page 18 for details.
这篇关于如何使用RSA加密数据,使用SHA-256作为散列函数和MGF1作为掩码生成函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!