public void RSAIntegrationTest() { int[] ints = { 123, 234, 233, 323, 999, 888, 245, 101, 100, 1000, 1999 }; foreach (var m in ints) { string[] keys = controller.Get_Keys(); var publicKey = keys[0]; var privateKey = keys[1]; var modulus = keys[2]; Console.WriteLine("Initial Message: " + m); var encryptedMessage = controller.Encrypt(m.ToString(), publicKey, modulus); Console.WriteLine("Encrypted Message: " + encryptedMessage); var decryptedMessage = controller.Decrypt(encryptedMessage, privateKey, modulus); Console.WriteLine("Decrypted Message: " + decryptedMessage); Assert.AreEqual(m.ToString(), decryptedMessage); } }
private static void Main(string[] args) { string _publicKey = "<RSAKeyValue><Modulus>i6BFZEiowigxEIV/2SUNUTjgslJas0Qe5pqi1qG6CZvyS25ruyZ67FHQw6mSHg22tZ/sfTBWSuS2LU+9QaqVuw==" + "</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>"; Console.WriteLine("Please enter the Password you want to have Encrypted: "); string passwordPlain = Console.ReadLine(); string passwordEncrypted = RSAController.Encrypt(passwordPlain, _publicKey); Console.WriteLine(""); Console.WriteLine("Your Encrypted Password is: " + passwordEncrypted); string m_exePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); try { using (StreamWriter sw = new StreamWriter(m_exePath + "\\Encrypted.txt", true)) { sw.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(), DateTime.Now.ToLongDateString()); sw.WriteLine(" "); sw.WriteLine(" {0}", passwordEncrypted); sw.WriteLine("-------------------------------"); } Console.WriteLine("Note: the Password has also been saved into the Encryptet.txt"); } catch (Exception) { } Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine("Pressy Any Key to exit :)"); Console.ReadKey(); }