我可以使用RSACryptoServiceProvider公钥/私钥与Crypto ++互操作吗?

时间:2022-03-13 22:55:38

I've created a public/private key using RSACryptoServiceProvider and saved it as XML. I can use this to encrypt/decrypt/sign and verify data in .NET.

我使用RSACryptoServiceProvider创建了一个公钥/私钥,并将其保存为XML。我可以使用它来加密/解密/签名并验证.NET中的数据。

I have another application which is intended to run on a Linux server. I'm developing it in C++ and I'm using Crypto++ for my cryptography needs.

我有另一个应用程序,它可以在Linux服务器上运行。我正在用C ++开发它,我正在使用Crypto ++来满足我的加密需求。

I want to share data between these two applications, but to do that I need to convert the RSAParameters into public/private keys that Crypto++ can understand.

我想在这两个应用程序之间共享数据,但为此我需要将RSAParameters转换为Crypto ++可以理解的公钥/私钥。

I'm also open to using convert public/private keys generated by Crypto++ into RSAParameters if it is easier to do.

如果更容易做的话,我也愿意将Crypto ++生成的转换公钥/私钥用于RSAParameters。

Any ideas?

1 个解决方案

#1


The easiest way is probably to use the RSAParameters directly instead of going over XML.

最简单的方法可能是直接使用RSAParameters而不是通过XML。

Just store the byte-arrays contained in the RSAParameters in a file using a format of your own choice. Read the byte-arrays back in your C++ program and create CryptoPP::Integers from them. Use those Integers to Initialize a RSAFunction (public key) or InvertibleRSAFunction (private key).

只需使用您自己选择的格式将RSAParameters中包含的字节数组存储在文件中。在C ++程序中读取字节数组并从中创建CryptoPP :: Integers。使用这些整数初始化RSAFunction(公钥)或InvertibleRSAFunction(私钥)。

The reverse way is similiar: I.e.

相反的方式是类似的:I.e。

RSAFunction publicKey = ...;

size_t modulusLength = publicKey.getModulus().ByteCount();
unsigned char * modulus = new unsigned char[modulusLength];
publicKey.getModulus().Encode(modulus, modulusLength);

// similarly with PublicExponent and remember to clean up the arrays.

and transfer the arrays to your .NET-application, where you can use them to initialize an RSAParameters.

并将数组传输到.NET应用程序,您可以使用它们来初始化RSAParameters。

#1


The easiest way is probably to use the RSAParameters directly instead of going over XML.

最简单的方法可能是直接使用RSAParameters而不是通过XML。

Just store the byte-arrays contained in the RSAParameters in a file using a format of your own choice. Read the byte-arrays back in your C++ program and create CryptoPP::Integers from them. Use those Integers to Initialize a RSAFunction (public key) or InvertibleRSAFunction (private key).

只需使用您自己选择的格式将RSAParameters中包含的字节数组存储在文件中。在C ++程序中读取字节数组并从中创建CryptoPP :: Integers。使用这些整数初始化RSAFunction(公钥)或InvertibleRSAFunction(私钥)。

The reverse way is similiar: I.e.

相反的方式是类似的:I.e。

RSAFunction publicKey = ...;

size_t modulusLength = publicKey.getModulus().ByteCount();
unsigned char * modulus = new unsigned char[modulusLength];
publicKey.getModulus().Encode(modulus, modulusLength);

// similarly with PublicExponent and remember to clean up the arrays.

and transfer the arrays to your .NET-application, where you can use them to initialize an RSAParameters.

并将数组传输到.NET应用程序,您可以使用它们来初始化RSAParameters。