Asymmetric encryption uses two keys—a public key and a private key. Because of this, it runs bit slowly. Also, it is necessary to keep the private key safe at all times. Unless you have the private key, you cannot decrypt the message.
Now, let's jump into an example and try to understand how this is done. In this scenario, we will be using RSACryptoServiceProvider. This algorithm provides us with public and private keys that can be used to encrypt and decrypt messages. The encrypt method accepts a public key and text to encrypt, and we then convert the text to a byte array since the encrypt method accepts byte arrays. Then, we set the public key for the algorithm and invoke the encrypt method:
public static byte[] EncryptAsymmetric(string publicKey, string texttoEncrypt)
{
byte[] result;
UnicodeEncoding uc = new UnicodeEncoding();
byte...