Asymmetric encryption seems to be simpler than symmetric encryption in theory, but the details in practical applications are much more complex, in order to be understood from the very simple. NET, this section is a step-by-step understanding of the details.
Asymmetric key
When an instance of the class is created with an asymmetric encryption class, the constructor generates a "public/private key" pair. We can choose whether to save the key and how to save it.
Familiarize yourself with the key structure of the asymmetric key from the contents of code listing 6-8 first.
Code listing 6-8 Output asymmetric key
Class Program {staticvoid Main (string[] args) {Rsacryptoserviceprov
Ider rcp = new RSACryptoServiceProvider (); RSAParameters parameter1 = rcp.
Exportparameters (TRUE); RSAParameters parameter2 = rcp.
Exportparameters (FALSE);
Writeparameinfo (Parameter1, "parameter1");
Writeparameinfo (Parameter2, "parameter2");
Console.read (); } privatestaticvoid writeparameinfo (rsaparameters parameter,string name) {Cons Ole. WriteLine (name+).
D: "); Console.WriteLine (converbittostring) (parameter.
D));
Console.WriteLine (name+ "DP:"); Console.WriteLine (converbittostring) (parameter.
DP)); Console.WriteLine (name+).
DQ "); Console.WriteLine (converbittostring) (parameter.
DQ)); Console.WriteLine (name+).
Inverseq "); Console.WriteLine (Converbittostring (paramEter.
INVERSEQ)); Console.WriteLine (name+).
Modulus "); Console.WriteLine (converbittostring) (parameter.
modulus)); Console.WriteLine (name+).
P "); Console.WriteLine (converbittostring) (parameter.
P)); Console.WriteLine (name+).
Q "); Console.WriteLine (converbittostring) (parameter.
Q)); Console.WriteLine (name +).
Exponent "); Console.WriteLine (converbittostring) (parameter.
Exponent));
} publicstaticstring converbittostring (byte[] bytes) {if (bytes = null)
{return "This value is empty!";}
else {StringBuilder sb = new StringBuilder (); for (int i = 0; i < bytes. Length; i++) {sb. Append (Bytes[i].
ToString ()); Return SB.
ToString ();
} }
}