.Net pass code

I have a strange problem. I am working on a .net windows project using C # code. I am trying to encrypt / decrypt files using public / private keys. This has happened to me several times since I started working on encryption. The actual question of how to get encryption to work will be another post later.

The problem is that when my code runs, the pointer exits the subroutine. It does not crash and does not fall into the try / catch block.

In the example below, the row to get the public key works, but the row to get the private key does not work. it just skips and returns to the calling module.

string publicKey; // gets the public key
string privateKey; // gets the private key
try
{
    CspParameters cspParam = new CspParameters();
    cspParam.Flags = CspProviderFlags.UseMachineKeyStore;
    System.Security.Cryptography.RSACryptoServiceProvider RSA =
        new System.Security.Cryptography.RSACryptoServiceProvider(cspParam);
    //        The key information
    //from the cspParam object above can be saved via
    //select the;
    publicKey = RSA.ToXmlString(false); // gets the public key
    privateKey = RSA.ToXmlString(true); // gets the private key
    string x = publicKey;
}
catch (Exception ex)
{
    clsGetMessage.DisplayError(ex);
}
+3
source share
2 answers

VS? , , ?

VS .

+2

PrivateKey , , ?

0

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


All Articles