This demo contains two files, builds a solution, and then builds two files, one for form, one for Class, copy the code to the correct execution process: Envelope decryption: 1, get the key, here is here Generate a key, and the actual application can read the key 2, encrypt 3, decrypt the signature and verification from various storage media: Signature: 1, get the key, here is a key, the actual application can be used from various storage Read the key 2 on the medium, get the HASH code 3 to be signed, the signature, 1 and 2 steps do not matter, in this case, we will sign the contents of TXTSource or sign the files: 1. Get the key, here is a key, and the actual application can read the key 2 from various storage media, get the Hash code 3 to be verified, get the string of the signature, here the string skewers are stored in In the m_strencryptedsignatureData variable, you must get this string through the signature in Demo, so you need to perform the signature, of course, you can also get 4 other ways, verify, 1 and 2 steps, in this example, us Signing the contents of TXTSource, or you can sign the file. If it is a file, you can get the contents of the file in a BYTE [] method after obtaining the file. ////Rsacryption.cs///uSing System Using system.text; using system.security.cryptography;
Namespace RsaApplication {///
PUBLIC RSACryption () {// // Todo: Add constructor logic here //} #ENDREGION #Region RSA encryption decryption
#region RSA key generation of the RSA key generation // // private and public keys generated public void RSAKey (out string xmlKeys, out string xmlPublicKey) {try {System.Security.Cryptography.RSACryptoServiceProvider rsa = new RSACryptoServiceProvider () XmlKeys = RSA.TOXMLSTRING (TRUE); XMLPublicKey = RSA.TOXMLSTRING (FALSE);} catch (exception ex) {throw ex;}} #endregion #REGION RSA encryption function // ######### ######################################################################################################################################################################################################################################################################################################## ############### 加 加 // Description Key must be a row of XML, return is a string // there is a point to explain! ! This encryption method has a length limit! ! / / ############################################################################### #############################################
// RSA encryption function public string RSAEncrypt (string xmlPublicKey, string m_strEncryptString) {try {byte [] PlainTextBArray; byte [] CypherTextBArray; string Result; System.Security.Cryptography.RSACryptoServiceProvider rsa = new RSACryptoServiceProvider (); rsa.FromXmlString ( xmlPublicKey); PlainTextBArray = (new UnicodeEncoding ()) GetBytes (m_strEncryptString);. CypherTextBArray = rsa.Encrypt (PlainTextBArray, false); Result = Convert.ToBase64String (CypherTextBArray); return Result;} catch (Exception ex) {throw ex; }} // RSA encryption function public string RSAEncrypt (string xmlPublicKey, byte [] encryptString) {try {byte [] CypherTextBArray; string Result; System.Security.Cryptography.RSACryptoServiceProvider rsa = new RSACryptoServiceProvider (); rsa.FromXmlString (xmlPublicKey ); Cyphertextbarray = RSA.Encrypt (EncryptString, false); result = communication.tobase64string (cyphertextbarray); return result;} catch (exception ex) {throw ex; } #Endregion
#region RSA decryption function // RSA decryption function public string RSADecrypt (string xmlPrivateKey, string m_strDecryptString) {try {byte [] PlainTextBArray; byte [] DypherTextBArray; string Result; System.Security.Cryptography.RSACryptoServiceProvider rsa = new RSACryptoServiceProvider ( ); rsa.FromXmlString (xmlPrivateKey); PlainTextBArray = Convert.FromBase64String (m_strDecryptString); DypherTextBArray = rsa.Decrypt (PlainTextBArray, false); Result = (new UnicodeEncoding ().) GetString (DypherTextBArray); return Result;} catch (Exception ex) {throw ex;}} // RSA decryption function public string RSADecrypt (string xmlPrivateKey, byte [] DecryptString) {try {byte [] DypherTextBArray; string Result; System.Security.Cryptography.RSACryptoServiceProvider rsa = new RSACryptoServiceProvider () Rsa.fromlstring (xmlprivatekey); dyphertextbarray = rsa.decrypt (decryptstring, false); result = (new unicodeEncoding ()). GetString (DyphertextBarray); returnrate;} catch CEPTION EX) {throw ex;}} # endregion # endRegion
#REGION RSA Digital Sign
#Region Get a Hash Description Table / / Get Hash Description Table PUBLIC BOOL GETHASH (String M_STRSource, Ref Byte [] HashData) {Try {// Get Hash from String Byte [] Buffer; System.Security.cryptography.hashalgorithm MD5 = System.Security.Cryptography.HashAlgorithm.Create ( "MD5"); Buffer = System.Text.Encoding.GetEncoding ( "GB2312") GetBytes (m_strSource);. HashData = MD5.ComputeHash (Buffer); return true;} catch Exception ex) {throw ex;}}
// Get Hash description public bool GetHash (string m_strSource, ref string strHashData) {try {// obtain Hash Description byte [] Buffer from the string; byte [] HashData; System.Security.Cryptography.HashAlgorithm MD5 = System. Security.Cryptography.HashAlgorithm.Create ( "MD5"); Buffer = System.Text.Encoding.GetEncoding ( "GB2312") GetBytes (m_strSource);. HashData = MD5.ComputeHash (Buffer); strHashData = Convert.ToBase64String (HashData) Return true;} catch (exception ex) {throw ex;}} // Get a Hash description table public bool getHash (System.IO.FileStream Objfile, ref byte [] hashdata) {try {// From the file acquired Hash description System.Security.Cryptography.HashAlgorithm MD5 = System.Security.Cryptography.HashAlgorithm.Create ( "MD5"); HashData = MD5.ComputeHash (objFile); objFile.Close (); return true;} catch (Exception ex) {throw EX;}}
// Get Hash description public bool GetHash (System.IO.FileStream objFile, ref string strHashData) {try {// obtain Hash Description byte [] HashData from the file; System.Security.Cryptography.HashAlgorithm MD5 = System.Security. Cryptography.hashalgorithm.create ("MD5"); hashdata = md5.computehash (objfile); objfile.close ();
StrhashData = Convert.TOBASE64String (hashdata);
Return true;} catch (exception ex) {throw ex;}} #ENDREGON
#region RSA signature // RSA signature public bool SignatureFormatter (string p_strKeyPrivate, byte [] HashbyteSignature, ref byte [] EncryptedSignatureData) {try {System.Security.Cryptography.RSACryptoServiceProvider RSA = new System.Security.Cryptography.RSACryptoServiceProvider ();
RSA.FromXmlString (p_strKeyPrivate); System.Security.Cryptography.RSAPKCS1SignatureFormatter RSAFormatter = new System.Security.Cryptography.RSAPKCS1SignatureFormatter (RSA); // set the signature algorithm is MD5 RSAFormatter.SetHashAlgorithm ( "MD5"); // execute signature EncryptedSignatureData = RSAFORMATTER.CREATESIGNATURE (HashBytesignature); return true;} catch (exception ex) {throw ex;}}
// RSA Sign PUBLIC BOOL SIGNATUREFORMATTER (String P_StrKeyPrivate, Byte [] Hashbytesignature, Ref string m_strencryptedSignatureData) {Try {byte [] encryptedSignatureData;
System.security.cryptography.rsacryptoserviceProvider RSA = new system.security.cryptography.rsacryptoServiceProvider ();
RSA.FromXmlString (p_strKeyPrivate); System.Security.Cryptography.RSAPKCS1SignatureFormatter RSAFormatter = new System.Security.Cryptography.RSAPKCS1SignatureFormatter (RSA); // set the signature algorithm is MD5 RSAFormatter.SetHashAlgorithm ( "MD5"); // execute signature EncryptedSignatureData = Rsaformatter.createsignature (hashbytesignature);
M_strencryptedsignatureData = Convert.TOBASE64String (EncryptedSignatureData);
Return true;} catch (exception ex) {throw ex;}}
// RSA Signature Public Bool SignatureFormatter (String M_StrKeyPrivate, String M_StrHashbytester, ref byte [] encryptedsignatureData) {Try {byte [] hashbytesignature;
HashbyteSignature = Convert.FromBase64String (m_strHashbyteSignature); System.Security.Cryptography.RSACryptoServiceProvider RSA = new System.Security.Cryptography.RSACryptoServiceProvider ();
RSA.FromXmlString (p_strKeyPrivate); System.Security.Cryptography.RSAPKCS1SignatureFormatter RSAFormatter = new System.Security.Cryptography.RSAPKCS1SignatureFormatter (RSA); // set the signature algorithm is MD5 RSAFormatter.SetHashAlgorithm ( "MD5"); // execute signature EncryptedSignatureData = RSAFORMATTER.CREATESIGNATURE (HashBytesignature); return true;} catch (exception ex) {throw ex;}}
// RSA signature public bool SignatureFormatter (string p_strKeyPrivate, string m_strHashbyteSignature, ref string m_strEncryptedSignatureData) {try {byte [] HashbyteSignature; byte [] EncryptedSignatureData;
HashbyteSignature = Convert.FromBase64String (m_strHashbyteSignature); System.Security.Cryptography.RSACryptoServiceProvider RSA = new System.Security.Cryptography.RSACryptoServiceProvider ();
RSA.FromXmlString (p_strKeyPrivate); System.Security.Cryptography.RSAPKCS1SignatureFormatter RSAFormatter = new System.Security.Cryptography.RSAPKCS1SignatureFormatter (RSA); // set the signature algorithm is MD5 RSAFormatter.SetHashAlgorithm ( "MD5"); // execute signature EncryptedSignatureData = Rsaformatter.createsignature (hashbytesignature);
M_strencryptedsignatureData = Convert.TOBASE64String (EncryptedSignatureData);
Return true;} catch (exception ex) {throw ex;}} #ENDREGON
#Region RSA Signature Verification
public bool SignatureDeformatter (string p_strKeyPublic, byte [] HashbyteDeformatter, byte [] DeformatterData) {try {System.Security.Cryptography.RSACryptoServiceProvider RSA = new System.Security.Cryptography.RSACryptoServiceProvider ();
RSA.FromXmlString (p_strKeyPublic); System.Security.Cryptography.RSAPKCS1SignatureDeformatter RSADeformatter = new System.Security.Cryptography.RSAPKCS1SignatureDeformatter (RSA); // specify when the decryption algorithm HASH MD5 RSADeformatter.SetHashAlgorithm ( "MD5"); if (RSADeformatter .Verifysignature (hashBytedeformatter, deformatterdata) {return true;}}} catch (exception ex) {throw ex;}}
Public Bool SignatureDeformatter (String P_StrKeyPublic, string p_strhashbytedeformatter, byte [] deformatterdata) {Try {byte [] hashbytedeformatter;
HashBytedeformatter = Convert.FromBase64String (p_strhashbytedeformatter);
System.security.cryptography.rsacryptoserviceProvider RSA = new system.security.cryptography.rsacryptoServiceProvider ();
RSA.FromXmlString (p_strKeyPublic); System.Security.Cryptography.RSAPKCS1SignatureDeformatter RSADeformatter = new System.Security.Cryptography.RSAPKCS1SignatureDeformatter (RSA); // specify when the decryption algorithm HASH MD5 RSADeformatter.SetHashAlgorithm ( "MD5");
IF (Hashibytedeformatter, DeformatterData) {Return True;} else {return false;}} catch (exception ex) {throw ex;}}
Public Bool SignatureDeformatter (String P_StrKeypublic, Byte [] hashbytedeformatter, string p_strdeformatterdata) {Try {byte [] deformatterdata;
System.security.cryptography.rsacryptoserviceProvider RSA = new system.security.cryptography.rsacryptoServiceProvider ();
RSA.FromXmlString (p_strKeyPublic); System.Security.Cryptography.RSAPKCS1SignatureDeformatter RSADeformatter = new System.Security.Cryptography.RSAPKCS1SignatureDeformatter (RSA); // specify when the decryption algorithm HASH MD5 RSADeformatter.SetHashAlgorithm ( "MD5"); DeformatterData = Convert .Frombase64string (p_strdeformatterdata);
IF (Hashibytedeformatter, DeformatterData) {Return True;} else {return false;}} catch (exception ex) {throw ex;}}
Public Bool SignatureDeformatter (string p_str readypublic, string p_strhashbytedeformatter, string p_strdeformatterdata) {try {byte [] deformatterdata; Byte [] hashbytedeformatter;
HashbyteDeformatter = Convert.FromBase64String (p_strHashbyteDeformatter); System.Security.Cryptography.RSACryptoServiceProvider RSA = new System.Security.Cryptography.RSACryptoServiceProvider ();
RSA.FromXmlString (p_strKeyPublic); System.Security.Cryptography.RSAPKCS1SignatureDeformatter RSADeformatter = new System.Security.Cryptography.RSAPKCS1SignatureDeformatter (RSA); // specify when the decryption algorithm HASH MD5 RSADeformatter.SetHashAlgorithm ( "MD5");
DEFORMATTERDATA = Convert.FromBase64String (p_strdeformatterdata);
IF (Hashibytedeformatter, DeformatterData) {Return True;} else {return false;}} catch (exception ex) {throw ex;}}
#ENDREGION #ENDREGION
}} //// frMrsacryptiontest.cs /// using system; use system.drawing; use system.collections; using system.componentmodel; using system.windows.form;
Summary description of Namespace RsaApplication {///
private System.Windows.Forms.Button btnDeformatter; private System.Windows.Forms.Button btnGetHashSignature; private System.Windows.Forms.Button btnGetHashDeformatter; private System.Windows.Forms.TextBox txtSignature; private System.Windows.Forms.TextBox txtGetHashSignature; Private system.windows.Forms.TextBox txtgethashdeformatter;
PRIVATE STRING M_STRKEYPRIVATE = "" "; private string m_str availablepublic =" "
Private string m_strhashbytesignature = ""; private string m_strhashbytedeformatter = ""; private string m_strencryptedsignatureData = "; #ENDREGION
#REGION Construction Function Public FRMRSACRYPTIONTEST () {/// // Windows Form Designer Support for // InitializationComponent ();
// // Todo: Add any constructor code after INITIALIZEComponent call //}
///
/// summary> private void InitializeComponent () {this.btnBuildKey = new System.Windows.Forms.Button (); this.txtKeyPublic = new System.Windows.Forms.TextBox (); this.txtKeyPrivate = new System. Windows.Forms.TextBox (); this.btnRSAEncrypt = new System.Windows.Forms.Button (); this.txtSource = new System.Windows.Forms.TextBox (); this.txtRSAEncrypt = new System.Windows.Forms.TextBox (); this.txtRSADecrypt = new System.Windows.Forms.TextBox (); this.btnRSADecrypt = new System.Windows.Forms.Button (); this.btnDeformatter = new System.Windows.Forms.Button (); this. btnSignature = new System.Windows.Forms.Button (); this.txtSignature = new System.Windows.Forms.TextBox (); this.btnGetHashSignature = new System.Windows.Forms.Button (); this.btnGetHashDeformatter = new System. Windows.Forms.Button (); this.txtGetHashSignature = new System.Windows.Forms.TextBox (); this.txtGetHashDeformatter = new System.Windows.Forms.TextBox (); this.SuspendLayout (); // // btnBuildKey // this.btnbuildkey.location = new system.drawing.point (11, 17); this.btnbuildkey.name = "btnbuildkey"; this.btnbuildkey.size = new system.drawing.size (77, 34); this. btnBuildKey.TabIndex = 0; this.btnBuildKey.Text = "generates a key"; this.btnBuildKey.Click = new System.EventHandler (this.btnBuildKey_Click); // // txtKeyPublic // this.txtKeyPublic.Location = new System .Drawing.Point (137, 11); this.txtKeyPublic.Multiline = true; this.txtKeyPublic.Name = "txtKeyPublic"; this.txtKeyPublic.Size = new System.Drawing.Size (602, 44); this.txtKeyPublic. TabINDEX = 1;
this.txtKeyPublic.Text = ""; // // txtKeyPrivate // this.txtKeyPrivate.Location = new System.Drawing.Point (137, 58); this.txtKeyPrivate.Multiline = true; this.txtKeyPrivate.Name = "txtKeyPrivate "; this.txtKeyPrivate.Size = new System.Drawing.Size (602, 44); this.txtKeyPrivate.TabIndex = 2; this.txtKeyPrivate.Text =" "; // // btnRSAEncrypt // this.btnRSAEncrypt.Location = new System.Drawing.Point (11, 157); this.btnRSAEncrypt.Name = "btnRSAEncrypt"; this.btnRSAEncrypt.Size = new System.Drawing.Size (77, 34); this.btnRSAEncrypt.TabIndex = 3; this. btnRSAEncrypt.Text = "RSA encryption"; this.btnRSAEncrypt.Click = new System.EventHandler (this.btnRSAEncrypt_Click); // // txtSource // this.txtSource.Location = new System.Drawing.Point (137, 108) THIS.TXTSOURCE.MULTILINE = true; this.txtsource.name = "txtsource"; this.txtsource.size = new system.drawing.size (602, 44); this.txtsource.tabindex = 4; this.txtsource.text = "String can't be too long J-km, .ewm.m, .vkj China Fujian "; // // txtRSAEncrypt // this.txtRSAEncrypt.Location = new System.Drawing.Point (137, 155); this.txtRSAEncrypt.Multiline = true; this.txtRSAEncrypt.Name =" txtRSAEncrypt "; this.txtRSAEncrypt. Size = new System.Drawing.Size (602, 44); this.txtRSAEncrypt.TabIndex = 5; this.txtRSAEncrypt.Text = ""; // // txtRSADecrypt // this.txtRSADecrypt.Location = new System.Drawing.Point (137, 203); this.txtrsadecrypt.multiline = true; this.txtrsadecrypt.name = "txtrsadecrypt"; this.txtrsademadept.size =
new System.Drawing.Size (602, 44); this.txtRSADecrypt.TabIndex = 6; this.txtRSADecrypt.Text = ""; // // btnRSADecrypt // this.btnRSADecrypt.Location = new System.Drawing.Point (11 , 202); this.btnRSADecrypt.Name = "btnRSADecrypt"; this.btnRSADecrypt.Size = new System.Drawing.Size (77, 34); this.btnRSADecrypt.TabIndex = 7; this.btnRSADecrypt.Text = "RSA decryption" ; this.btnRSADecrypt.Click = new System.EventHandler (this.btnRSADecrypt_Click); // // btnDeformatter // this.btnDeformatter.Location = new System.Drawing.Point (11, 396); this.btnDeformatter.Name = " btnDeformatter "; this.btnDeformatter.Size = new System.Drawing.Size (77, 34); this.btnDeformatter.TabIndex = 10; this.btnDeformatter.Text =" RSA authentication "; this.btnDeformatter.Click = new System. EventHandler (this.btnDeformatter_Click); // // btnSignature // this.btnSignature.Location = new System.Drawing.Point (11, 297); this.btnSignature.Name = "btnSignature"; this.btnSignature.Size = new Syste M. Drawing.Size (77, 34); this.btnsignature.tabindex = 9; this.btnsignature.text = "RSA signature"; this.btnsignature.click = new system.eventhandler (this.btnsignature_click); // / / txtSignature // this.txtSignature.Location = new System.Drawing.Point (137, 298); this.txtSignature.Multiline = true; this.txtSignature.Name = "txtSignature"; this.txtSignature.Size = new System.Drawing .Size (602, 44); this.txtSignature.tabindex = 11; this.txtSignature.text = ""; /// btngethashsignature // this.btnemeshsisature.location =
new System.Drawing.Point (11, 252); this.btnGetHashSignature.Name = "btnGetHashSignature"; this.btnGetHashSignature.Size = new System.Drawing.Size (117, 36); this.btnGetHashSignature.TabIndex = 13; this. btnGetHashSignature.Text = "Get Ha dilute code (signature)"; this.btnGetHashSignature.Click = new System.EventHandler (this.btnGetHashSignature_Click); // // btnGetHashDeformatter // this.btnGetHashDeformatter.Location = new System.Drawing.Point (11, 348); this.btnGetHashDeformatter.Name = "btnGetHashDeformatter"; this.btnGetHashDeformatter.Size = new System.Drawing.Size (117, 36); this.btnGetHashDeformatter.TabIndex = 14; this.btnGetHashDeformatter.Text = "Get Ha thin code (authentication) "; this.btnGetHashDeformatter.Click = new System.EventHandler (this.btnGetHashDeformatter_Click); // // txtGetHashSignature // this.txtGetHashSignature.Location = new System.Drawing.Point (137, 251); THIS.TXTGETHSIGNATURE.MULTILINE = true; this.txtgethashSignature.Name = "txtgethashsignature"; this.txt GetHashSignature.Size = new System.Drawing.Size (602, 44); this.txtGetHashSignature.TabIndex = 15; this.txtGetHashSignature.Text = ""; // // txtGetHashDeformatter // this.txtGetHashDeformatter.Location = new System.Drawing .Point (137, 346); this.txtGetHashDeformatter.Multiline = true; this.txtGetHashDeformatter.Name = "txtGetHashDeformatter"; this.txtGetHashDeformatter.Size = new System.Drawing.Size (602, 44); this.txtGetHashDeformatter.TabIndex = 16; this.txtgethashdeformatter.text = ""; ///frsacryptiontest // this.autoscalebasesize =
New system.drawing.size (6, 14); this.clientsize = new system.drawing.size (764, 444); this.Controls.add (this.txtgethashdeformatter); this.controls.add (this.txtgethashSignature); THISCONTROLS.ADD (this.txtros.add (this.txtrsadecrypt); this.controls.add (this.txtrsaencrypt); this.controls.add (this.txtsource); this.controls.add ( this.txtKeyPrivate); this.Controls.Add (this.txtKeyPublic); this.Controls.Add (this.btnGetHashDeformatter); this.Controls.Add (this.btnGetHashSignature); this.Controls.Add (this.btnDeformatter); this .Controls.Add (this.btnSignature); this.Controls.Add (this.btnRSADecrypt); this.Controls.Add (this.btnRSAEncrypt); this.Controls.Add (this.btnBuildKey); this.Name = "frmRSACryptionTest" "This.Text =" RSA Encryption Decryption "; this.ResumeLayout (false);} #ENDREGION
#REGION application's primary invested point ///
#REGION generates a key
Private void btnbuildkey_click (object sender, system.eventargs e) {
Try {racryption rc = new rsacryption ();
Rc.rskey (out m_stroyalprivate, out m_str readypublic);
this.txtKeyPrivate.Text = m_strKeyPrivate; this.txtKeyPublic.Text = m_strKeyPublic;} catch (Exception ex) {MessageBox.Show (this, ex.Message, "error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows .Form.MessageBoxicon.Error);}} #ENDREGION
#region encryption decryption
Private void btnrsaencrypt_click (object sender, system.eventAcryption rc = new {racryption rc = new {rsacryption ();
this.txtRSAEncrypt.Text = RC.RSAEncrypt (m_strKeyPublic, this.txtSource.Text);} catch (Exception ex) {MessageBox.Show (this, ex.Message, "error", System.Windows.Forms.MessageBoxButtons.OK, System.windows.Forms.MessageBoxicon.Error);}} private void btnrsadecrypt_click (object sender, system.eventargs e) {try {racryption rc = new};
this.txtRSADecrypt.Text = RC.RSADecrypt (m_strKeyPrivate, this.txtRSAEncrypt.Text);} catch (Exception ex) {MessageBox.Show (this, ex.Message, "error", System.Windows.Forms.MessageBoxButtons.OK, System.windows.Forms.MessageBoxicon.Error);}}
#ndregion
#Region signature, verification
#Region Get the Hash code --- for the signature
Private void btngethashsignature_click (object sender, system.eventAcryption rc = new {racryption rc = new {rsacryption ();
IF (rc.gethash (this.txtsource.text, ref m_strhashbytester == false) {MessageBox.show (this, "Take a Hash code error!", "Tips", System.Windows.form, System. Windows.Forms.MessageBoxicon.warning);
this.txtGetHashSignature.Text = m_strHashbyteSignature;} catch (Exception ex) {MessageBox.Show (this, ex.Message, "error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } #ENDREGION
#REGON Sign Private Void Btnsignature_Click (Object Sender, System.Eventargs E) {Try {RSacryption Rc = New Rsacryption ();
if (RC.SignatureFormatter (m_strKeyPrivate, m_strHashbyteSignature, ref m_strEncryptedSignatureData) == false) {MessageBox.Show (this, "RSA Digital Signature wrong!", "tips", System.Windows.Forms.MessageBoxButtons.OK, System.Windows. Forms.MessageBoxicon.warning);
this.txtSignature.Text = m_strEncryptedSignatureData;} catch (Exception ex) {MessageBox.Show (this, ex.Message, "error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); }} # Endregion # region Get a Hash code --- For Validation Private Void BtNgetHashDeformatter_Click (Object Sender, System.Eventargs E) {Try {Rsacryption Rc = New Rsacryption ();
IF (rc.gethash (this.txtsource.text, ref m_strhashibytedeformatter) == false) {MessageBox.show (this, "Take a Hash code error!", "Tips", System.Windows.form, System ,. SYSTEM. Windows.Forms.MessageBoxicon.warning);
this.txtGetHashDeformatter.Text = m_strHashbyteDeformatter;} catch (Exception ex) {MessageBox.Show (this, ex.Message, "error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } #ENDREGION
#Region Verify Private Void Btndeformatter_Click (Object Sender, System.EventArgs E) {Try {RSacryption Rc = New Rsacryption ();
if (RC.SignatureDeformatter (m_strKeyPublic, m_strHashbyteDeformatter, m_strEncryptedSignatureData) == false) {MessageBox.Show (this, "Authentication failed!", "tips", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms. MessageBoxicon.Warning);} else {MessageBox.show (this, "Authentication)," Tips ", System.Windows.MMS.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxicon.warning);}} catch Exception ex) {messagebox.show (this, ex.Message, "error", system.windows.forms.MessageBoxButtons.ok, system.windows.forms.MessageBoxicon.Error);}} #ENDREGION
#ndregion
}