static void Main(string[] args) { Encoding encoding = new UTF8Encoding(); RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(); byte[] plainText; byte[] cypherText; Console.WriteLine("Textul pentru criptare"); var text = Console.ReadLine(); if (!string.IsNullOrEmpty(text)) { plainText = encoding.GetBytes(text); var rsaParam = rsa.ExportParameters(false); cypherText = RsaEnc.Encrypt(plainText, rsa.ExportParameters(false), false); var encryptedText = encoding.GetString(cypherText); Console.WriteLine("Text Criptat: " + encryptedText); Console.WriteLine("Enter pentru decriptare"); Console.ReadLine(); byte[] decryptedText = RsaEnc.Decrypt(cypherText, rsa.ExportParameters(true), false); Console.WriteLine("Text decriptat: " + encoding.GetString(decryptedText)); Console.ReadLine(); } }
static void Main(string[] args) { RsaEnc rs = new RsaEnc(); string cypher = String.Empty; Console.WriteLine($"PublicKey: \n {rs.PublicKeyString()}"); Console.WriteLine("Enter your text to encrypt"); var text = Console.ReadLine(); if (text != String.Empty) { cypher = rs.Encrypt(text); Console.WriteLine($"Cypher Text: \n{cypher} \n"); } Console.WriteLine("Press Enter to decrypt"); Console.ReadLine(); var plaintext = rs.Decrypt(cypher); Console.WriteLine("Decrypted Text: \n"); Console.WriteLine(plaintext); Console.ReadLine(); }