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