将代码从c++移植到使用RSA pkcs# 1私钥加密
Porting code from c++ to Encrypting with RSA PKCS#1 private key
我正在尝试将这段代码从c++移植到c#:
...
strPrivateKey = "someBase64EncodedPrivateKey";
long sizeKey = DecodeBase64(strPrivateKey, pKey);
const unsigned char* _pKey = pKey;
d2i_RSAPrivateKey(&pRSA, &_pKey, sizeKey);
...
RSA_private_encrypt(sizeOfMessage, pMessage, pSignature, pRSA, RSA_PKCS1_PADDING);
...
到目前为止,我的代码如下:
var strPrivateKey = "someBase64EncodedPrivateKey";
var bytes = Convert.FromBase64String(strPrivateKey);
var rsa = new RSACryptoServiceProvider();
// How to set the private key to the rsa object?!
byte[] someDataToEncrypt = /* Set the data to encrypt */;
var encryptedData = rsa.Encrypt(someDataToEncrypt, false);
编辑:我不确定这是否是我应该参考的类。
谢谢
rsarapameters (http://msdn.microsoft.com/en-us/library/system.security.cryptography.rsaparameters.aspx)可以使用ImportParameters方法提供给RSACryptoServiceProvider类。您可以在rparparameters结构中对键进行编码。
添加:
At the begin of the private key: "-----BEGIN RSA PRIVATE KEY-----rn"
After each line of my private key : "rn"
At the end of my private key: "-----END RSA PRIVATE KEY-----"
最后,我使用了OpenSsl。. NET作为库。这篇文章最初解决了我的问题:使用OpenSSL解密RSA。. NET中已有键
相关文章:
- SSH通过/sbin/SSH无法读取RSA密钥文件(从控制台运行)
- 如何使用Crypto++并为RSA返回可打印的字节/字符数组
- WinCrypt RSA vs Java org.bouncycastle
- 使用 char 数组公钥的 OpenSSL 进行 RSA 加密
- 从加密项目向量中解密任意选择的元素会导致无效的 PKCS #7 块错误
- OpenSSL RSA 解密随机失败 C/C++
- C# 中的 RSA 签名和 Crypto++ C++中的验证
- 如何通过 Crypto++ 和 RSA 对文件进行签名
- C++ 和 node.js 之间的 RSA 加密
- 从字符串 Crypto++ 导入 RSA 公钥/私钥
- 在加密++中使用RSA加密对称AES密钥
- C++项目需要什么才能使用证书 (RSA-SHA256) 对文件进行签名
- C++生成 RSA 密钥对并读取
- RSA 加密和解密期间的随机数生成器要求
- 博坦加载现有的 RSA 私钥
- 计算 RSA 并以十六进制格式保存到文件
- StreamTransformationFilter:使用 AES 解密找到的无效 PKCS #7 块填充
- 使用C 和WinCrypt库的RSA NCRYPTICT和C#解密
- RSA PKCS#1 V2.1在C++中的实现
- 将代码从c++移植到使用RSA pkcs# 1私钥加密