Asymmetric encryption (4). NET Asymmetric Encryption Practice

Source: Internet
Author: User
Tags modulus tostring asymmetric encryption

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 ();
    
   }     }
    
    } 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.