如何使用 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 ?
推荐答案
以下摘录允许将 OAEP 和 SHA256 用于 MGF 和哈希函数.使用 OpenSSL 1.0.2L 测试
The following excerpt allows using OAEP with SHA256 for both the MGF and hash function. Tested with OpenSSL 1.0.2L
int flags = CMS_BINARY | CMS_PARTIAL | CMS_KEY_PARAM;
cms = CMS_encrypt(NULL, in, cipher, flags)
ri = CMS_add1_recipient_cert(cms, cert, flags);
pctx = CMS_RecipientInfo_get0_pkey_ctx(ri);
EVP_PKEY_CTX_set_rsa_padding(pctx, RSA_PKCS1_OAEP_PADDING);
EVP_PKEY_CTX_set_rsa_oaep_md(pctx, EVP_sha256());
EVP_PKEY_CTX_set_rsa_mgf1_md(pctx, EVP_sha256());
这篇关于如何使用 RSA 加密数据,使用 SHA-256 作为哈希函数,MGF1 作为掩码生成函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!