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


C# SymmetricAlgorithm.GenerateKey方法代码示例

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


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

示例1: Secure

        static Secure()
        {
            try
            {
                var secureSettings = MassiveDB.Current.FindSettings("Secure");
                algorithm = new RijndaelManaged();

                if (secureSettings.Count() != 2)
                {
                    MassiveDB.Current.RemoveDomainSettings("Secure");

                    algorithm.GenerateIV();
                    algorithm.GenerateKey();

                    MassiveDB.Current.InsertDomainSetting("Secure", "IV", Convert.ToBase64String(algorithm.IV));
                    MassiveDB.Current.InsertDomainSetting("Secure", "Key", Convert.ToBase64String(algorithm.Key));
                }
                else
                {
                    algorithm.IV = Convert.FromBase64String(secureSettings.Single(s => s.Identifier == "IV").SettingValue);
                    algorithm.Key = Convert.FromBase64String(secureSettings.Single(s => s.Identifier == "Key").SettingValue);
                }
            }
            catch (Exception ex)
            {
                algorithm = null;
                initException = ex;
            }
        }
开发者ID:andywhitfield,项目名称:RunnersPal,代码行数:29,代码来源:Secure.cs

示例2: NetCryptoProviderBase

		public NetCryptoProviderBase(NetPeer peer, SymmetricAlgorithm algo)
			: base(peer)
		{
			m_algorithm = algo;
			m_algorithm.GenerateKey();
			m_algorithm.GenerateIV();
		}
开发者ID:KennethYap,项目名称:MonoGame,代码行数:7,代码来源:NetCryptoProviderBase.cs

示例3: AESCryptoKey

 /// <summary> Creates a new key </summary>
 public AESCryptoKey()
 {
     _key = new RijndaelManaged();
     _key.Padding = PaddingMode.PKCS7;
     _key.KeySize = 256;
     _key.IV = _iv ?? ProcessDefaultIV;
     _key.GenerateKey();
 }
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:9,代码来源:AESCryptoKey.cs

示例4: GenerateUnprotectedKey

 byte[] GenerateUnprotectedKey(SymmetricAlgorithm algorithm)
 {
     using (algorithm)
     {
         algorithm.GenerateKey();
         return algorithm.Key;
     }
 }
开发者ID:davinx,项目名称:himedi,代码行数:8,代码来源:SymmetricKeyGenerator.cs

示例5: cryptography

 public cryptography(bool IsConsole, bool oldExpansionMethod = false)
 {
     isConsole = IsConsole;
     oldFormatKeyExpansion = oldExpansionMethod;
     twoFish = new Twofish();
     twoFish.Mode = CipherMode.CBC;
     twoFish.GenerateIV();
     twoFish.GenerateKey();
 }
开发者ID:elaverick,项目名称:wincrypt,代码行数:9,代码来源:cryptography.cs

示例6: GenerateUnprotectedKey

		private byte[] GenerateUnprotectedKey(SymmetricAlgorithm algorithm)
		{
			byte[] generatedKey = null;

			using (algorithm)
			{
				algorithm.GenerateKey();
				generatedKey = algorithm.Key;
			}
			return generatedKey;
		}
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:11,代码来源:SymmetricKeyGenerator.cs

示例7: GetLegalKey

 /// <summary>
 /// 获得密钥
 /// </summary>
 /// <returns>密钥</returns>
 private static byte[] GetLegalKey(SymmetricAlgorithm mobjCryptoService)
 {
     string sTemp = "Cuz(%&hj7x89H$yuBI0456FtmaT5&fvHUFCy76*h%(HilJ$lhj!y6&(*jkP87jH1";
     mobjCryptoService.GenerateKey();
     byte[] bytTemp = mobjCryptoService.Key;
     int KeyLength = bytTemp.Length;
     if (sTemp.Length > KeyLength)
         sTemp = sTemp.Substring(0, KeyLength);
     else if (sTemp.Length < KeyLength)
         sTemp = sTemp.PadRight(KeyLength, ' ');
     return ASCIIEncoding.ASCII.GetBytes(sTemp);
 }
开发者ID:BaiMath,项目名称:ForKids,代码行数:16,代码来源:SymmetricMethod.cs

示例8: EncryptionEngine

		/// <summary>
		/// Initializes a new instance of the RegistrationEncryptionEngine class
		/// </summary>
		public EncryptionEngine()
		{
			_sa = DES.Create(); //Create();
			_sa.Padding = PaddingMode.PKCS7;
			_sa.Mode = CipherMode.ECB;
			_sa.GenerateKey();

			//			_sa.GenerateIV();
			//			byte[] iv = _sa.IV;

			_sa.IV = _iv;
		}
开发者ID:FireBall1725,项目名称:Razor.Framework,代码行数:15,代码来源:EncryptionEngine.cs

示例9: Build

        public void Build(SymmetricAlgorithm algorithm)
        {
            if (algorithm == null)
                throw new ArgumentNullException("algorithm");

            using (algorithm)
            {
                algorithm.KeySize = CurrentKeySize;
                algorithm.BlockSize = CurrentBlockSize;
                algorithm.Mode = SelectedCipher;
                algorithm.Padding = SelectedPadding;

                algorithm.GenerateIV();
                algorithm.GenerateKey();

                textBoxIV.Text = Convert.ToBase64String(algorithm.IV);
                textBoxKey.Text = Convert.ToBase64String(algorithm.Key);
            }
        }
开发者ID:lockflatboy,项目名称:AES-Builder,代码行数:19,代码来源:frmMain.cs

示例10: EncryptorType

 static void EncryptorType(SymmetricAlgorithm sa, string file_output, string file_input)
 {
     sa.GenerateKey();
     sa.GenerateIV();
     ICryptoTransform transform = sa.CreateEncryptor(sa.Key, sa.IV);
     using (FileStream file = new FileStream(file_output, FileMode.Create, FileAccess.Write))
     {
        using( CryptoStream stream = new CryptoStream(file, transform, CryptoStreamMode.Write))
         using (FileStream input = new FileStream(file_input, FileMode.Open))
         {
             input.CopyTo(stream);
         }
         using (StreamWriter key = new StreamWriter("file.key.txt"))
         {
             string s = Convert.ToBase64String(sa.IV);
             key.WriteLine(s);
             s = Convert.ToBase64String(sa.Key);
             key.Write(s);
         }
     }
 }
开发者ID:AlinaKapustina,项目名称:nsudotnet,代码行数:21,代码来源:Program.cs

示例11: EncryptString

 public static byte[] EncryptString(string source, SymmetricAlgorithm algorithm)
 {
     byte[] buffer;
     algorithm.GenerateIV();
     algorithm.GenerateKey();
     using (MemoryStream stream = new MemoryStream(0x80))
     {
         using (new BinaryWriter(stream))
         {
             stream.Write(algorithm.IV, 0, algorithm.IV.Length);
             stream.Write(algorithm.Key, 0, algorithm.Key.Length);
             using (CryptoStream stream2 = new CryptoStream(stream, algorithm.CreateEncryptor(), CryptoStreamMode.Write))
             {
                 using (TextWriter writer2 = new StreamWriter(stream2))
                 {
                     writer2.Write(source);
                 }
             }
             buffer = stream.ToArray();
         }
     }
     return buffer;
 }
开发者ID:shankithegreat,项目名称:commanderdotnet,代码行数:23,代码来源:SimpleEncrypt.cs

示例12: GenerarClave

 private static void GenerarClave(SymmetricAlgorithm algoritmo)
 {
     // Establecemos la longitud que queremos que tenga la clave a generar.
     algoritmo.KeySize = 256;
     Console.WriteLine("Longitud de la clave: {0}", algoritmo.KeySize);
     Console.WriteLine("Pulse una tecla para continuar…\n");
     Console.ReadKey();
     // Leer sin más el valor de la clave hara que se genere.
     // sacamos la clave por consola
     Console.WriteLine("La clave: ");
     foreach (byte b in algoritmo.Key)
     {
         Console.Write("{0:X2} ", b);
     }
     Console.WriteLine("\nPulse una tecla para continuar…\n");
     Console.ReadKey();
     // Podemos generar otra nueva
     algoritmo.GenerateKey();
     // sacamos la nueva clave por consola
     Console.WriteLine("Otra clave: ");
     foreach (byte b in algoritmo.Key)
     {
         Console.Write("{0:X2} ", b);
     }
     Console.WriteLine("\nPulse una tecla para continuar…\n");
     Console.ReadKey();
     // Otra forma de crear claves sería con RNG (Random Number Generator)
     RandomNumberGenerator randomNumberGenerator =
         RandomNumberGenerator.Create();
     // Se rellena el array de bytes de la clave con datos aleatorios
     randomNumberGenerator.GetBytes(algoritmo.Key);
     // sacamos la clave por consola
     Console.WriteLine("Otra forma de obtener una clave: ");
     foreach (byte b in algoritmo.Key)
     {
         Console.Write("{0:X2} ", b);
     }
     Console.WriteLine("\nPulse una tecla para continuar…\n");
     Console.ReadKey();
 }
开发者ID:sancas,项目名称:ProgramacionIII,代码行数:40,代码来源:Program.cs

示例13: SetEncryptor

        private void SetEncryptor() {
            switch (_mbytEncryptionType) {
                case SymmetricEncryptType.Des:
                    _mCsp = new DESCryptoServiceProvider();
                    break;

                case SymmetricEncryptType.Rc2:
                    _mCsp = new RC2CryptoServiceProvider();
                    break;

                case SymmetricEncryptType.Rijndael:
                    _mCsp = new RijndaelManaged();
                    break;

                case SymmetricEncryptType.TripleDes:
                    _mCsp = new TripleDESCryptoServiceProvider();
                    break;
            }
            _mCsp.GenerateKey();
            _mCsp.GenerateIV();
        }
开发者ID:wolfweb,项目名称:Ww,代码行数:21,代码来源:EncryptManager.cs

示例14: GetLegalKey

        private byte[] GetLegalKey(SymmetricAlgorithm cryptoObj)
        {
            if (string.IsNullOrEmpty(key))
                key = DEFAULT_KEY;

            string sTemp = key;
            cryptoObj.GenerateKey();
            byte[] bytTemp = cryptoObj.Key;
            int KeyLength = bytTemp.Length;
            if (sTemp.Length > KeyLength)
                sTemp = sTemp.Substring(0, KeyLength);
            else if (sTemp.Length < KeyLength)
                sTemp = sTemp.PadRight(KeyLength, ' ');
            return ASCIIEncoding.ASCII.GetBytes(sTemp);
        }
开发者ID:netcasewqs,项目名称:nlite,代码行数:15,代码来源:Cryptographer.cs

示例15: GenerateSymmetricKey

 /// <summary>
 /// Generates the symmetric key.
 /// </summary>
 /// <param name="algorithm">The algorithm.</param>
 /// <returns></returns>
 public static byte[] GenerateSymmetricKey(SymmetricAlgorithm algorithm)
 {
     algorithm.GenerateKey();
     return algorithm.Key;
 }
开发者ID:BclEx,项目名称:AdamsyncEx,代码行数:10,代码来源:SecurityEx.cs


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