Created
February 19, 2022 18:48
-
-
Save rabieedev1996/196a92c50ffa7342ec32b55fa0d3d5e5 to your computer and use it in GitHub Desktop.
Rsa encryption in c#
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static string Encrypt(string plainText, string publicKey) | |
| { | |
| UnicodeEncoding _encoder = new UnicodeEncoding(); | |
| var rsa = new RSACryptoServiceProvider(); | |
| rsa.FromXmlString(publicKey); | |
| var dataToEncrypt = _encoder.GetBytes(plainText); | |
| var encryptedByteArray = rsa.Encrypt(dataToEncrypt, false).ToArray(); | |
| return Convert.ToBase64String(encryptedByteArray); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment