// <PackageReference Include="Twileloop.ExpressSecurity" Version="1.0.0" /> //RSA Encryption // 1) generate a key pair public static void Run() { var fullPath = AppDomain.CurrentDomain.BaseDirectory; var rootPath = fullPath.Replace("\\bin\\Debug\\net5.0", ""); var directorySeparatorChar = Path.DirectorySeparatorChar.ToString(); var mainDir = "RSA Encryption" + directorySeparatorChar; var publicKey_Path = Path.Combine(rootPath, mainDir, "RSAPublic.key"); var privateKey_Path = Path.Combine(rootPath, mainDir, "RSAPrivate.key"); RSAEncription.MakeKey(publicKey_Path, privateKey_Path); var text = "this is awesome"; Console.WriteLine($"Nomal text => {text}"); var cypherText = RSAEncription.EncryptString(text, publicKey_Path); Console.WriteLine($"Encryption => {cypherText}"); var decryptedText = RSAEncription.EncryptString(cypherText, privateKey_Path); Console.WriteLine($"Decryption => {decryptedText}"); }
//RSA Encription/Description private static void RSAKeyEncription() { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("RSA ENCRIPTION ---------------------------------------"); Console.WriteLine(@"Location to store public key? (Eg: C:\publickey.rsa)"); var publicKey = Console.ReadLine(); Console.WriteLine(@"Location to store private key? (Eg: C:\privatekey.rsa)"); var privateKey = Console.ReadLine(); Console.WriteLine("Generating public key and private key..."); RSAEncription.MakeKey(publicKey, privateKey); Console.WriteLine("Enter text to be encripted"); var input = Console.ReadLine(); Console.WriteLine($"RSA Encripting... (With public key)"); var ciphertext = RSAEncription.EncryptString(input, publicKey); Console.WriteLine("RSA Encripted - " + ciphertext); Console.WriteLine($"RSA Decripting... (With private key)"); var text = RSAEncription.DecryptString(ciphertext, privateKey); Console.WriteLine("RSA Decripted - " + text); }