OpenSSL (cpp) 和 .net RSA 密钥交换
我有一个关于 OpenSSL 和 dotnet 加密的问题。我想将 OpenSSL 生成的 RSA 公钥和私钥转换为 dotnet 密钥。然后该键用于执行进一步的操作。出于安全原因,使用外部密钥库或密钥文件不是解决方案。我已经包含了我必须使用的旧 cpp 代码的一小部分,并标记了两行,我认为可以导出密钥。 RSA密钥结构来自外部PKI服务器。事实上,PKI 服务器在发送消息时为选定的用户提供一系列公钥。每个用户的私钥始终存储在本地。有人可以帮助我吗?
非常感谢
沃尔克的帮助
############## start code ##############
typedef struct _KEY_POINT
{
unsigned short size;
unsigned short key_size;
unsigned long crc;
unsigned char key_data[1];
} KEY_POINT, * PKEY_POINT;
unsigned char * encryptRSA( const unsigned char * pSrcBuffer,
unsigned long * pBufferSize,
const PKEY_POINT pPublicKey)
{
RSA * pRsa = NULL;
// -----snip ----------------
unsigned char * pPublic_data = pPublicKey->key_data;
pRsa = d2i_RSAPublicKey(&pRsa, (const unsigned char **)&pPublic_data, pPublicKey->key_size);
// Here chance to export *pRsa as .net public keye e.g. as string (base 64 encoded)
// -----snip ----------------
}
unsigned char * decryptRSA( const unsigned char * pSrcBuffer,
unsigned long * pBufferSize,
const PKEY_POINT pPrivateKey)
{
RSA * pRsa = NULL;
// -----snip ----------------
unsigned char * pPublic_data = pPublicKey->key_data;
pRsa = d2i_RSAPrivateKey(&pRsa, (const unsigned char **)&pPublic_data, pPublicKey->key_size);
// Here chance to export *pRsa as .net private key e.g. as string (base 64 encoded)
// -----snip ----------------
}
############## end code ##############
I have a problem concerning OpenSSL and dotnet encryption. I would like to transform a RSA public and private key generated by OpenSSL into a dotnet one. This key is then used for further actions. For security reasons the usage of an external keystore or keyfile is not a solution. I have included a small part of an old cpp code I have to use and have marked two lines where I think it is possible to export the keys. The RSA key structure comes from an extenal PKI server. In fact the PKI server delivers an array of public keys for selected users when sending a message. The private key for each user is always stored local. Could one help me?
Thanks a lot for your help
Volker
############## start code ##############
typedef struct _KEY_POINT
{
unsigned short size;
unsigned short key_size;
unsigned long crc;
unsigned char key_data[1];
} KEY_POINT, * PKEY_POINT;
unsigned char * encryptRSA( const unsigned char * pSrcBuffer,
unsigned long * pBufferSize,
const PKEY_POINT pPublicKey)
{
RSA * pRsa = NULL;
// -----snip ----------------
unsigned char * pPublic_data = pPublicKey->key_data;
pRsa = d2i_RSAPublicKey(&pRsa, (const unsigned char **)&pPublic_data, pPublicKey->key_size);
// Here chance to export *pRsa as .net public keye e.g. as string (base 64 encoded)
// -----snip ----------------
}
unsigned char * decryptRSA( const unsigned char * pSrcBuffer,
unsigned long * pBufferSize,
const PKEY_POINT pPrivateKey)
{
RSA * pRsa = NULL;
// -----snip ----------------
unsigned char * pPublic_data = pPublicKey->key_data;
pRsa = d2i_RSAPrivateKey(&pRsa, (const unsigned char **)&pPublic_data, pPublicKey->key_size);
// Here chance to export *pRsa as .net private key e.g. as string (base 64 encoded)
// -----snip ----------------
}
############## end code ##############
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您拥有 DER 格式的数据(我假设这是因为您使用 d2i_RSAXXX),也许您可以使用 base64 函数, http://www.ioncannon.net/programming/34/howto-base64-encode-with-cc-and-openssl/。
这还假设 .Net 可以读取 DER 格式的公钥和私钥。
Since you have the data in DER format (I assume this since you use d2i_RSAXXX), maybe you can use the base64 function, http://www.ioncannon.net/programming/34/howto-base64-encode-with-cc-and-openssl/.
That also assumes .Net can read public and private keys in DER format.