OpenSSL (cpp) 和 .net RSA 密钥交换

发布于 2024-11-26 18:28:55 字数 1608 浏览 2 评论 0原文

我有一个关于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Oo萌小芽oO 2024-12-03 18:28:55

由于您拥有 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文