コード例 #1
0
ファイル: RSAEncoder.cs プロジェクト: L2N6H5B3/SoftSled2
        // Create an RSAPKCS1KeyExchangeDeformatter object with a new RSA key.
        // Display its properties to the console.
        public void ConstructDeformatter()
        {
            // Construct an empty OAEP key exchange.
            RSAPKCS1KeyExchangeDeformatter rsaDeformatter =
                new RSAPKCS1KeyExchangeDeformatter();

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

            rsaDeformatter.SetKey(key);

            RNGCryptoServiceProvider ring = new RNGCryptoServiceProvider();

            rsaDeformatter.RNG = ring;

            Console.WriteLine();
            Console.WriteLine("**" + rsaDeformatter.ToString() + "**");

            string xmlParameters = rsaDeformatter.Parameters;

            Console.WriteLine();
            Console.WriteLine("The RSA deformatter has the following ");
            Console.WriteLine("parameters:" + xmlParameters);
        }
コード例 #2
0
        public void Properties()
        {
            RSAPKCS1KeyExchangeDeformatter keyex = new RSAPKCS1KeyExchangeDeformatter();

            keyex.SetKey(key);
            Assert.IsNull(keyex.Parameters, "RSAPKCS1KeyExchangeDeformatter.Parameters");
            // null (default)
            Assert.IsNull(keyex.RNG, "RSAPKCS1KeyExchangeDeformatter.RNG");
            Assert.AreEqual("System.Security.Cryptography.RSAPKCS1KeyExchangeDeformatter", keyex.ToString());
        }
コード例 #3
0
        /// <summary>
        /// Decrypts the target key with the CryptoManager's private RSA key.  It is assumbed that the
        /// @rijKey was previously encrypted with the CryptoManager's public key.
        /// </summary>
        /// <param name="rijKey"></param>
        /// <returns></returns>
        public byte[] DecryptRijndaelKey(byte[] rijKey)
        {
            byte[] key = new byte[0];
            lock (this)
            {
                //m_RSA.ImportCspBlob(m_PrivateKey);
                m_RSA.FromXmlString(Encoding.UTF8.GetString(m_PrivateKey));
                m_RSA_Exch_Def.SetKey(m_RSA);
                key = m_RSA_Exch_Def.DecryptKeyExchange(rijKey);
            }

            return(key);
        }