当前位置: 首页>>代码示例>>C#>>正文


C# RSACryptoServiceProvider.Clear方法代码示例

本文整理汇总了C#中System.Security.Cryptography.RSACryptoServiceProvider.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# RSACryptoServiceProvider.Clear方法的具体用法?C# RSACryptoServiceProvider.Clear怎么用?C# RSACryptoServiceProvider.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Cryptography.RSACryptoServiceProvider的用法示例。


在下文中一共展示了RSACryptoServiceProvider.Clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        public override void Run()
        {
            RSACryptoServiceProvider rsa = null;
            try
            {
                var cp = new CspParameters();
                cp.KeyContainerName = _containerName;
                cp.Flags = CspProviderFlags.UseMachineKeyStore;

                rsa = new RSACryptoServiceProvider(cp);
                rsa.FromXmlString(File.ReadAllText(_keyFile));
                rsa.PersistKeyInCsp = true;
                rsa.Clear();
            }
            catch (Exception)
            {
                if (rsa != null)
                {
                    rsa.PersistKeyInCsp = false;
                    rsa.Clear();
                }

                throw;
            }
        }
开发者ID:namelesstwice,项目名称:NConfiguration,代码行数:25,代码来源:Import.cs

示例2: GenKeys

 private static RSACryptoServiceProvider GenKeys(int keySize)
 {
     var parameters = new CspParameters();
     RSACryptoServiceProvider provider;
     parameters.Flags = CspProviderFlags.NoPrompt | CspProviderFlags.UseMachineKeyStore | CspProviderFlags.UseExistingKey;
     parameters.KeyNumber = (int)KeyNumber.Exchange;
     parameters.KeyContainerName = System.Reflection.Assembly.GetEntryAssembly().FullName;
     try
     {
         //RSAHelper: Attempting to open existing key container
         provider = new RSACryptoServiceProvider(parameters);
         var pa = provider.ExportParameters(false);
         if (pa.Modulus.Length * 8 == keySize) return provider;
         //Found existing key, but not of the correct size
         provider.PersistKeyInCsp = false;
         provider.Clear();
         provider.Dispose();
         GenerateRsaKeys(parameters, keySize, out provider);
     }
     catch
     {
         //No existing Key Container was found in the machine keystore
         GenerateRsaKeys(parameters, keySize, out provider);
     }
     finally
     {
         GC.Collect();
         GC.WaitForPendingFinalizers();
     }
     return provider;
 }
开发者ID:Melamew,项目名称:iLynx.Common,代码行数:31,代码来源:RsaKeyExchangeAlgorithm.cs

示例3: RSACryptoServiceProviderTest

	public RSACryptoServiceProviderTest () 
	{
		sha1OID = CryptoConfig.MapNameToOID ("SHA1");
		disposed = new RSACryptoServiceProvider (minKeySize);
		disposed.FromXmlString ("<RSAKeyValue><Modulus>vtXAf62+o50prNCTiVGTMzdhm4sMjK0QVDkKQLFGu2fJQCULt9NZBab14PiWfG1t</Modulus><Exponent>AQAB</Exponent><P>5y2AHOzIhTChIFzLsgZQAGfy3U8OPwFh</P><Q>01NUVJJv+hhIsnbFiSi24FLRrfr/qYuN</Q><DP>HKLAOdUCyazKaK3V9Yleo448wTkntJpB</DP><DQ>AH5MTxo8arAN02TVlzliG+n1lVtlp2at</DQ><InverseQ>ZpgJwTxSYpT81sQCuVUvX0AYrvSziNIw</InverseQ><D>CStiJYBmsZvincAj5qw5w3M8yGmE/9ls4yv7wenozzC4kZshpI2MuON0d2Z8f4aB</D></RSAKeyValue>");
		disposed.Clear ();
	}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:7,代码来源:RSACryptoServiceProviderTest.cs

示例4: CreateKey

 /// <summary>
 /// ������˽Կ
 /// </summary>
 /// <param name="publicKey"></param>
 /// <param name="privatekey"></param>
 public void CreateKey(out string publicKey, out string privateKey)
 {
     RSACryptoServiceProvider crypt = new RSACryptoServiceProvider();
     publicKey = crypt.ToXmlString(false);
     privateKey = crypt.ToXmlString(true);
     crypt.Clear();
 }
开发者ID:jquery2005,项目名称:GMIS,代码行数:12,代码来源:DataProtection.cs

示例5: Main

        static void Main(string[] args)
        {
            string KeyContainerName = "MyKeyContainer";
            string clearText = "This is the data we want to encrypt!";
            CspParameters cspParams = new CspParameters();
            cspParams.KeyContainerName = KeyContainerName;

            RSAParameters publicKey;
            RSAParameters privateKey;

            using(var rsa = new RSACryptoServiceProvider(cspParams))
            {
                rsa.PersistKeyInCsp = true;
                publicKey = rsa.ExportParameters(false);
                privateKey = rsa.ExportParameters(true);

                rsa.Clear();
            }

            byte[] encrypted = EncryptUsingRSAParam(clearText, publicKey);
            string decrypted = DecryptUsingRSAParam(encrypted, privateKey);

            Console.WriteLine("Asymmetric RSA - Using RSA Params");
            Console.WriteLine("Encrypted:{0}", Convert.ToBase64String(encrypted));
            Console.WriteLine("Decrypted:{0}", decrypted);

            Console.WriteLine("Asymmetric RSA - Using Persistent Key Container");
            encrypted = EncryptUsingContainer(clearText, KeyContainerName);
            decrypted = DecryptUsingContainer(encrypted, KeyContainerName);

            Console.WriteLine("Encrypted:{0}", Convert.ToBase64String(encrypted));
            Console.WriteLine("Decrypted:{0}", decrypted);

            Console.ReadLine();
        }
开发者ID:jbijoux,项目名称:Exam-70-483,代码行数:35,代码来源:Program.cs

示例6: RSADeleteKeyInCSP

        public static void RSADeleteKeyInCSP(string ContainerName)
        {
            try
            {
                // Create a new instance of CspParameters.  Pass
                // 13 to specify a DSA container or 1 to specify
                // an RSA container.  The default is 1.
                CspParameters cspParams = new CspParameters();

                // Specify the container name using the passed variable.
                cspParams.KeyContainerName = ContainerName;

                //Create a new instance of RSACryptoServiceProvider.
                //Pass the CspParameters class to use the
                //key in the container.
                RSACryptoServiceProvider RSAalg = new RSACryptoServiceProvider(cspParams);

                //Delete the key entry in the container.
                RSAalg.PersistKeyInCsp = false;

                //Call Clear to release resources and delete the key from the container.
                RSAalg.Clear();

                //Indicate that the key was persisted.
                Console.WriteLine("The RSA key was deleted from the container, \"{0}\".", ContainerName);
            }
            catch (CryptographicException e)
            {
                Console.WriteLine(e.Message);

            }
        }
开发者ID:277594531,项目名称:RSACSPSample,代码行数:32,代码来源:Program.cs

示例7: Decrypt

 /// <summary>
 /// Decrypts a string using RSA
 /// </summary>
 /// <param name="Input">Input string (should be small as anything over 128 bytes can not be decrypted)</param>
 /// <param name="Key">Key to use for decryption</param>
 /// <returns>A decrypted string</returns>
 public static string Decrypt(string Input, string Key)
 {
     RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
     RSA.FromXmlString(Key);
     byte[] InputArray = Convert.FromBase64String(Input);
     byte[] EncryptedBytes = RSA.Decrypt(InputArray, true);
     RSA.Clear();
     return Encoding.UTF8.GetString(EncryptedBytes);
 }
开发者ID:pengyancai,项目名称:cs-util,代码行数:15,代码来源:RSAEncryption.cs

示例8: GetKeyInfo

		/// <summary>
		/// 得到私匙和公匙的信息,string[0]是私匙的信息,string[1]是公匙的信息
		/// </summary>
		/// <returns></returns>
		public static string[] GetKeyInfo()
		{
			string[] key=new string[2];
			RSACryptoServiceProvider crypt=new RSACryptoServiceProvider();
			key[0]=crypt.ToXmlString(true);
			key[1]=crypt.ToXmlString(false);
			crypt.Clear();  
			return key;
		}
开发者ID:lyroge,项目名称:lyroge.framework,代码行数:13,代码来源:RSA.cs

示例9: GenerateRSAKey

 /// <summary>
 /// 生成密钥
 /// </summary>
 public RSAKey GenerateRSAKey()
 {
     RSAKey RSAKEY = new RSAKey();
     RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
     RSAKEY.PrivateKey = RSA.ToXmlString(true);    //生成私钥
     RSAKEY.PublicKey = RSA.ToXmlString(false);    //生成公钥
     RSA.Clear();
     return RSAKEY;
 }
开发者ID:ShiyxProjectCode,项目名称:EncryptionAndDecryption,代码行数:12,代码来源:RSAEncryptUtils.cs

示例10: Delete

 public static void Delete()
 {
     var cp = new CspParameters();
     cp.KeyContainerName = KeyContainerName;
     cp.Flags = CspProviderFlags.UseMachineKeyStore;
     var rsa = new RSACryptoServiceProvider(cp);
     rsa.PersistKeyInCsp = false; // Delete the key entry in the container.
     rsa.Clear();
 }
开发者ID:namelesstwice,项目名称:NConfiguration,代码行数:9,代码来源:KeyManager.cs

示例11: Encrypt

 /// <summary>
 /// Encrypts a string using RSA
 /// </summary>
 /// <param name="Input">Input string (should be small as anything over 128 bytes can not be decrypted)</param>
 /// <param name="Key">Key to use for encryption</param>
 /// <returns>An encrypted string (64bit string)</returns>
 public static string Encrypt(string Input, string Key)
 {
     RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
     RSA.FromXmlString(Key);
     ASCIIEncoding Encoding = new ASCIIEncoding();
     byte[] InputArray = Encoding.GetBytes(Input);
     byte[] EncryptedBytes = RSA.Encrypt(InputArray, true);
     RSA.Clear();
     return Convert.ToBase64String(EncryptedBytes);
 }
开发者ID:pengyancai,项目名称:cs-util,代码行数:16,代码来源:RSAEncryption.cs

示例12: FixtureSetUp

	public void FixtureSetUp () 
	{
		sha1OID = CryptoConfig.MapNameToOID ("SHA1");
		disposed = new RSACryptoServiceProvider (minKeySize);
		disposed.FromXmlString ("<RSAKeyValue><Modulus>vtXAf62+o50prNCTiVGTMzdhm4sMjK0QVDkKQLFGu2fJQCULt9NZBab14PiWfG1t</Modulus><Exponent>AQAB</Exponent><P>5y2AHOzIhTChIFzLsgZQAGfy3U8OPwFh</P><Q>01NUVJJv+hhIsnbFiSi24FLRrfr/qYuN</Q><DP>HKLAOdUCyazKaK3V9Yleo448wTkntJpB</DP><DQ>AH5MTxo8arAN02TVlzliG+n1lVtlp2at</DQ><InverseQ>ZpgJwTxSYpT81sQCuVUvX0AYrvSziNIw</InverseQ><D>CStiJYBmsZvincAj5qw5w3M8yGmE/9ls4yv7wenozzC4kZshpI2MuON0d2Z8f4aB</D></RSAKeyValue>");
		// FX 2.0 beta 1 bug - we must use the key before clearing it
		// http://lab.msdn.microsoft.com/ProductFeedback/viewfeedback.aspx?feedbackid=1bc807eb-c4ca-4c2d-8499-9f0470b71a29
		int ks = disposed.KeySize;
		disposed.Clear ();
	}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:10,代码来源:RSACryptoServiceProviderTest.cs

示例13: CifrarElemento

        /// <summary>
        /// 
        /// </summary>
        void CifrarElemento()
        {
            // Create an XmlDocument object.
            XmlDocument xmlDoc = new XmlDocument();

            // Load an XML file into the XmlDocument object.
            try
            {
                xmlDoc.PreserveWhitespace = true;
                xmlDoc.Load("ConfigurationManager.xml");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            // Create a new CspParameters object to specify
            // a key container.
            CspParameters cspParams = new CspParameters();
            cspParams.KeyContainerName = "XML_ENC_RSA_KEY";

            // Create a new RSA key and save it in the container.  This key will encrypt
            // a symmetric key, which will then be encryped in the XML document.
            RSACryptoServiceProvider rsaKey = new RSACryptoServiceProvider(cspParams);

            try
            {
                // Encrypt the "creditcard" element.
                Encrypt(xmlDoc, "Groups", "EncryptedElement1", rsaKey, "rsaKey");


                // Save the XML document.
                xmlDoc.Save("ConfigurationManager.xml");

                
     

            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                // Clear the RSA key.
                rsaKey.Clear();
            }


         



        }
开发者ID:spzenk,项目名称:sfdocsamples,代码行数:57,代码来源:Form1.cs

示例14: Create

        public static void Create()
        {
            var cp = new CspParameters();
            cp.KeyContainerName = KeyContainerName;
            cp.Flags = CspProviderFlags.UseMachineKeyStore;

            var rsa = new RSACryptoServiceProvider(cp);
            rsa.FromXmlString(XmlKey);
            rsa.PersistKeyInCsp = true;
            rsa.Clear();
        }
开发者ID:namelesstwice,项目名称:NConfiguration,代码行数:11,代码来源:KeyManager.cs

示例15: EncryptUsingRSAParam

        static byte[] EncryptUsingRSAParam(string value, RSAParameters rsaKeyInfo)
        {
            using(RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
            {
                rsa.ImportParameters(rsaKeyInfo);
                byte[] encodedData = Encoding.Default.GetBytes(value);
                byte[] encryptedData = rsa.Encrypt(encodedData, true);

                rsa.Clear();
                return encryptedData;
            }
        }
开发者ID:jbijoux,项目名称:Exam-70-483,代码行数:12,代码来源:Program.cs


注:本文中的System.Security.Cryptography.RSACryptoServiceProvider.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。