The rsa encryption algorithm is Shared using examples
Generates the private and public keysSystem.Security.Cryptography.RSACryptoServiceProvider myrsa = new RSACryptoServiceProvider();// Get the private key saved mainly RSAParameters In the 8 The parametersprivateKey = myrsa.ToXmlString(true);// I get the public key and I save it RSAParameters In the 2 A parameterpublicKey = myrsa.ToXmlString(false);RAS Realize the encryptionSystem.Security.Cryptography.RSACryptoServiceProvider myrsa = new RSACryptoServiceProvider();// To get the public keymyrsa.FromXmlString(publicKey);// Convert the content you want to encrypt to byte[]byte[] PlainTextBArray = (new UnicodeEncoding()).GetBytes(" Here's what you want to encrypt ");// use .NET In the Encrypt Method of encryptionbyte[] CypherTextBArray = myrsa.Encrypt(PlainTextBArray, false);// Finally, encrypt it byte[] Converted to Base64String , this is the encrypted contentResult = Convert.ToBase64String(CypherTextBArray)RAS Implement decryptionSystem.Security.Cryptography.RSACryptoServiceProvider myrsa = new RSACryptoServiceProvider();// Get the private keymyrsa.FromXmlString(xmlPrivateKey);// I'm going to encrypt it String Converted to byte[]byte[] PlainTextBArray = Convert.FromBase64String(" I just encrypted it string");// use .NET In the Decrypt Methods the decryptionbyte[] DypherTextBArray = myrsa.Decrypt(PlainTextBArray, false);// Convert after decryption byte[] , which brings us to our original pre-encrypted contentResult = (new UnicodeEncoding()).GetString(DypherTextBArray);byte[] messagebytes = Encoding.UTF8.GetBytes("luo ROM. "); RSACryptoServiceProvider oRSA = new RSACryptoServiceProvider(); string privatekey = oRSA.ToXmlString(true); string publickey = oRSA.ToXmlString(false); // The private key signature RSACryptoServiceProvider oRSA3 = new RSACryptoServiceProvider(); oRSA3.FromXmlString(privatekey); byte[] AOutput = oRSA3.SignData(messagebytes, "SHA1"); // A public key to verify RSACryptoServiceProvider oRSA4 = new RSACryptoServiceProvider(); oRSA4.FromXmlString(publickey); bool bVerify = oRSA4.VerifyData(messagebytes, "SHA1", AOutput);