예제 #1
0
        // Create an RSAPKCS1KeyExchangeFormatter object with a new RSA key.
        // Display its properties to the console.
        public void ConstructFormatter()
        {
            // Construct an empty Optimal Asymmetric Encryption Padding (OAEP)
            // key exchange.
            RSAPKCS1KeyExchangeFormatter rsaFormatter =
                new RSAPKCS1KeyExchangeFormatter();

            // Create an RSAKey and set it into the specified
            // RSAPKCS1KeyExchangeFormatter.
            RSA key = RSA.Create();

            rsaFormatter.SetKey(key);

            // Create a random number using RNGCryptoServiceProvider.
            RNGCryptoServiceProvider ring = new RNGCryptoServiceProvider();

            rsaFormatter.Rng = ring;

            Console.WriteLine();
            Console.WriteLine("**" + rsaFormatter.ToString() + "**");
            Console.Write("The following random number was generated using the ");
            Console.WriteLine("class:");
            Console.WriteLine(rsaFormatter.Rng);

            string xmlParameters = rsaFormatter.Parameters;

            Console.WriteLine();
            Console.WriteLine("The RSA formatter has the following parameters:");
            Console.WriteLine(rsaFormatter.Parameters);
        }
        public void Properties()
        {
            RSAPKCS1KeyExchangeFormatter keyex = new RSAPKCS1KeyExchangeFormatter();

            keyex.SetKey(key);
            AssertEquals("RSAPKCS1KeyExchangeFormatter.Parameters", "<enc:KeyEncryptionMethod enc:Algorithm=\"http://www.microsoft.com/xml/security/algorithm/PKCS1-v1.5-KeyEx\" xmlns:enc=\"http://www.microsoft.com/xml/security/encryption/v1.0\" />", keyex.Parameters);
            // null (default)
            AssertNull("RSAPKCS1KeyExchangeFormatter.Rng", keyex.Rng);
            AssertEquals("RSAPKCS1KeyExchangeFormatter.ToString()", "System.Security.Cryptography.RSAPKCS1KeyExchangeFormatter", keyex.ToString());
        }