Exemple #1
0
        static void Main(string[] args)
        {
            // Create an instance of the RSA algorithm class
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048);
            // Get the public keyy
            string publicKey  = rsa.ToXmlString(false); // false to get the public key
            string privateKey = rsa.ToXmlString(true);  // true to get the private key

            // Call the encryptText method
            EncryptText(publicKey, "Hello from Plataforma", "encryptedData.dat");

            Console.WriteLine("Public Key: {0}", publicKey);
            Console.WriteLine("");
            Console.WriteLine("Private Key: {0}", privateKey);
            Console.WriteLine("");

            // Call the decryptData method and print the result on the screen
            Console.WriteLine("Decrypted message: {0}", DecryptData(privateKey, "encryptedData.dat"));
            Console.WriteLine("");

            Console.WriteLine("TESTE CHAVE PRIVADA, IMPORTANDO FORMATO PEM");
            Console.WriteLine("");


            string chavepublica = rsa.ExportPemPublicKey();
            string chaveprivada = rsa.ExportPemPrivateKey();

            Console.WriteLine("Public Key: {0}", chavepublica);
            Console.WriteLine("");
            Console.WriteLine("Private Key: {0}", chaveprivada);
            Console.WriteLine("");

            rsa.ImportPemPrivateKey(PRIVATKEY);

            privateKey = rsa.ToXmlString(true); // true to get the private key

            // Call the decryptData method and print the result on the screen
            Console.WriteLine("Decrypted message with PEM: {0}", DecryptData(privateKey, "encryptedData.dat"));
            Console.WriteLine("");
        }