Using a previously generated RSA public / private key with .net framework

I have a pre-existing RSA encryption public / private key pair that I need to use in .net. All the examples that I can find on the Internet demonstrate how to create a new private / public pair and then encrypt / decrypt. i.e. something like that:

const int PROVIDER_RSA_FULL = 1;
const string CONTAINER_NAME = "SpiderContainer";
CspParameters cspParams;
cspParams = new CspParameters(PROVIDER_RSA_FULL);
cspParams.KeyContainerName = CONTAINER_NAME;
cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
cspParams.ProviderName = "Microsoft Strong Cryptographic Provider";
rsa = new RSACryptoServiceProvider(cspParams);
.....
rsa.encrypt(...)
rsa.decrypt(...)

As you can see, there is no way to skip to indicate an existing public / private key.

Does anyone know how to accomplish what I'm trying to do? Any help would be greatly appreciated.

Greetings Naren

+3
source share
2 answers

, ImportParameters -method:

RSAParameters parameters = new RSAParameters()
parameters.Modulus = // ...
parameters.Exponent = // ...
RSA rsa = new RSACryptoServiceProvider();
rsa.ImportParameters(parameters);
rsa.Encrypt(/*...*/);

, .

, , , . ( Xs, ).

+3

, , , , - ...

/ XML ( , , ).

:

this.RSAKey = RSA.FromXmlString(xmlString: myRSAXMLKey);

:

this.RSAKey_XMLString = RSA.ToXmlString(includePrivateParameters: false);
0

Source: https://habr.com/ru/post/1719470/


All Articles