C # RSA

Source: Internet
Author: User

RSA Plus decryption

Using System.Security.Cryptography;

    Private voidButton18_click (Objectsender, EventArgs e)//RSA Encryption        {            BOOLRsa_mode = radiobutton13.checked;//The Fill method is true to OAEP false to pkcs#1 1.5            stringRsa_message =Richtextbox15.text; Richtextbox12.text=""; byte[] Source = Encoding.Default.GetBytes (rsa_message);//convert plaintext to byte            byte[] ciphertext;//ciphertext byte array            stringPublicKey = Richtextbox17.text;//string KeyRSACryptoServiceProvider RSA =NewRSACryptoServiceProvider (); Try{RSA.                                Fromxmlstring (PublicKey); //Import String Keyciphertext = RSA. Encrypt (source, Rsa_mode);//EncryptStringBuilder SB =NewStringBuilder (); foreach(byteBinchciphertext) {sb. AppendFormat ("{0:x2}", B); } Richtextbox12.text=sb.                           ToString (); }            Catch{MessageBox.Show ("encryption failed, please check the key"); }        }    }
RSA Encryption
Private voidButton17_click (Objectsender, EventArgs e)//RSA Decryption        {            BOOLRsa_mode =radiobutton13.checked; stringRsa_ciphertext =Richtextbox12.text; Richtextbox15.text=""; stringPrivatekey =Richtextbox16.text; byte[] ciphertext =New byte[Rsa_ciphertext.length/2]; Try            {                 for(intx =0; X < Rsa_ciphertext.length/2; X + +)                {                    inti = (Convert.ToInt32 (rsa_ciphertext.substring (x *2,2), -)); CIPHERTEXT[X]= (byte) I; }            }            Catch{MessageBox.Show ("The cipher is not correct! "); }            byte[] source;//Original byte arrayRSACryptoServiceProvider RSA =NewRSACryptoServiceProvider (); Try{RSA.                          Fromxmlstring (Privatekey); //Setting the private keySource = RSA. Decrypt (ciphertext, rsa_mode);//decrypt, get byte arrayRichtextbox15.text = Encoding.Default.GetString (source);//return Results            }            Catch{MessageBox.Show ("The key is not correct"); }                    }
RSA Decryption

RSA keys in C # are not numbers, they are XML-formatted keys

It's encrypted with a special BASE64.

Http://www.cnblogs.com/midea0978/archive/2007/05/22/755826.html

C # Default Public key is 65537 that is aqab, do not know how to change

C # RSA

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.