private static void GenerateKey() { RSA encoder = new RSA(); encoder.GenerateKey(); // Создаем файл публичного ключа using (FileStream publicFileKey = new FileStream("PublicKey.txt", FileMode.Create)) //запись результата в файл { if (publicFileKey != null) { string publicKey = encoder.ImportPublicKey(); byte[] array = Encoding.UTF8.GetBytes(publicKey); publicFileKey.Write(array, 0, array.Length); Console.WriteLine("Файл публичного ключа создан"); } } // Создаем файл приватного ключа using (FileStream privateFileKey = new FileStream("PrivateKey.txt", FileMode.Create)) //запись результата в файл { if (privateFileKey != null) { string privateKey = encoder.ImportPrivateKey(); byte[] array = Encoding.UTF8.GetBytes(privateKey); privateFileKey.Write(array, 0, array.Length); Console.WriteLine("Файл секретного ключа создан"); } } }