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

前端 未结 2 1210
醉酒成梦
醉酒成梦 2020-12-11 04:56

I have a pre-existing public/private key pair for RSA encryption which I need to use in .net . All the examples I can find online demonstrate how to generate a new private/p

相关标签:
2条回答
  • 2020-12-11 05:31

    I realise this is a very old question but maybe someone still looks at this...

    Nowadays you can retrieve/store your keys in XML format (which you possibly could back in the days too).

    Example import:

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

    Example export:

    this.RSAKey_XMLString = RSA.ToXmlString(includePrivateParameters: false);
    
    0 讨论(0)
  • 2020-12-11 05:33

    To use an existing key, you can use the ImportParameters-method:

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

    You can add the private parameters, too, in order to use it for decrypting or signing.

    In order to tell you how to get from your existing keydata to the parameters, we need to know exactly how they are encoded. Try showing us the strings (replace most of the private key with Xs if it is a real key).

    0 讨论(0)
提交回复
热议问题