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


C# SymmetricAlgorithm.GenerateIV方法代码示例

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


在下文中一共展示了SymmetricAlgorithm.GenerateIV方法的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: 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

示例4: GetLegalIV

 /// <summary>
 /// 获得初始向量IV
 /// </summary>
 /// <returns>初试向量IV</returns>
 private static byte[] GetLegalIV(SymmetricAlgorithm mobjCryptoService)
 {
     string sTemp = "A4ghj*Ghg7!rNIfb&95GUY86GfghUb#er57HBh(u%g6HJ($jhWk7&!hg4ui%$hjo";
     mobjCryptoService.GenerateIV();
     byte[] bytTemp = mobjCryptoService.IV;
     int IVLength = bytTemp.Length;
     if (sTemp.Length > IVLength)
         sTemp = sTemp.Substring(0, IVLength);
     else if (sTemp.Length < IVLength)
         sTemp = sTemp.PadRight(IVLength, ' ');
     return ASCIIEncoding.ASCII.GetBytes(sTemp);
 }
开发者ID:BaiMath,项目名称:ForKids,代码行数:16,代码来源:SymmetricMethod.cs

示例5: 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

示例6: 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

示例7: 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

示例8: Encrypt

        internal static byte[] Encrypt(SymmetricAlgorithm crypter, byte[] data, byte[] cryptoKey, byte[] authKey, byte[] clearTextPayload)
        {
            byte[] cipherText;

            //Get an IV
            crypter.GenerateIV();
            byte[] iv = crypter.IV;

            //Encrypt Data
            using (var encrypter = crypter.CreateEncryptor(cryptoKey, iv))
            using (var cipherStream = new MemoryStream())
            {
                using (var cryptoStream = new CryptoStream(cipherStream, encrypter, CryptoStreamMode.Write))
                {
                    cryptoStream.Write(data, 0, data.Length);
                    cryptoStream.FlushFinalBlock();
                }

                cipherText = cipherStream.ToArray();
            }

            //Assemble encrypted message and add authentication
            using (var hmac = new HMACSHA256(authKey))
            using (var encryptedStream = new MemoryStream())
            {
                using (var binaryWriter = new BinaryWriter(encryptedStream))
                {
                    //Add clear text data first
                    if (clearTextPayload != null)
                    {
                        binaryWriter.Write(clearTextPayload);
                    }

                    //The add the IV
                    binaryWriter.Write(iv);

                    //Write Ciphertext
                    binaryWriter.Write(cipherText);

                    //Authenticate all data
                    var tag = hmac.ComputeHash(encryptedStream.ToArray());

                    //Append tag
                    binaryWriter.Write(tag);
                }

                return encryptedStream.ToArray();
            }
        }
开发者ID:Geminior,项目名称:DeepConfig,代码行数:49,代码来源:CryptoHelper.cs

示例9: SetKeyOnSymAlgorithm

 private void SetKeyOnSymAlgorithm(SymmetricAlgorithm symAlgo, byte[] dKey)
 {
     try
     {
         if ((dKey.Length > 8) && (symAlgo is DESCryptoServiceProvider))
         {
             byte[] dst = new byte[8];
             Buffer.BlockCopy(dKey, 0, dst, 0, 8);
             symAlgo.Key = dst;
             DestroyByteArray(dst);
         }
         else
         {
             symAlgo.Key = dKey;
         }
         symAlgo.GenerateIV();
         symAlgo.IV = new byte[symAlgo.IV.Length];
     }
     catch (Exception exception)
     {
         throw new ConfigurationErrorsException(System.Web.SR.GetString("Bad_machine_key", new object[] { exception.Message }), base.ElementInformation.Properties["decryptionKey"].Source, base.ElementInformation.Properties["decryptionKey"].LineNumber);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:23,代码来源:MachineKeySection.cs

示例10: GetLegalIV

        private byte[] GetLegalIV(SymmetricAlgorithm cryptoObj)
        {
            if (string.IsNullOrEmpty(iv))
                return null;//iv = DEFAULT_IV;

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

示例11: SetKeyOnSymAlgorithm

 private void SetKeyOnSymAlgorithm(SymmetricAlgorithm symAlgo, byte[] dKey)
 {
     try {
         if (dKey.Length > 8 && symAlgo is DESCryptoServiceProvider) {
             byte[] bTemp = new byte[8];
             Buffer.BlockCopy(dKey, 0, bTemp, 0, 8);
             symAlgo.Key = bTemp;
             DestroyByteArray(bTemp);
         } else {
             symAlgo.Key = dKey;
         }
         symAlgo.GenerateIV();
         symAlgo.IV = new byte[symAlgo.IV.Length];
     } catch (Exception e) {
         throw new ConfigurationErrorsException(SR.GetString(SR.Bad_machine_key, e.Message), ElementInformation.Properties["decryptionKey"].Source, ElementInformation.Properties["decryptionKey"].LineNumber);
     }
 }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:17,代码来源:MachineKeySection.cs

示例12: GetLegalIV

 private byte[] GetLegalIV(SymmetricAlgorithm mobjCryptoService)
 {
     string sTemp = _defaultLegalIV;
     mobjCryptoService.GenerateIV();
     byte[] bytTemp = mobjCryptoService.IV;
     int IVLength = bytTemp.Length;
     if (sTemp.Length > IVLength)
         sTemp = sTemp.Substring(0, IVLength);
     else if (sTemp.Length < IVLength)
         sTemp = sTemp.PadRight(IVLength, ' ');
     return ASCIIEncoding.ASCII.GetBytes(sTemp);
 }
开发者ID:Oman,项目名称:Maleos,代码行数:12,代码来源:CryptographyManager.cs

示例13: SymmetricAlgorithmProvider

 /// <summary>
 /// Creates an instance with a specified algorithm and key.
 /// </summary>
 /// <param name="algorithm">The algorithm to use for cryptographic functions.</param>
 /// <param name="key">The key to use for this algorithm.</param>
 public SymmetricAlgorithmProvider(SymmetricAlgorithm algorithm, byte[] key)
 {
     this.algorithm = algorithm;
     algorithm.Key = key;
     algorithm.GenerateIV();
     IVSize = algorithm.IV.Length;
 }
开发者ID:nehawadhwa,项目名称:ccweb,代码行数:12,代码来源:SecureQueryString.cs

示例14: CreateBase64IV

        /// <summary>
        /// Creates a random IV value appropriate for
        /// the encryption algorithm
        /// </summary>
        /// <param name="encryptionAlgorithm">Instance of SymmetricAlgorithm used to create the IV</param>
        /// <returns>Base64 encoded byte array containing the IV value</returns>
        protected static string CreateBase64IV(SymmetricAlgorithm encryptionAlgorithm)
        {
            byte[] iv = null;
            try
            {
              encryptionAlgorithm.GenerateIV();
              iv = encryptionAlgorithm.IV;

            }
            finally
            {
              encryptionAlgorithm.Clear();
              ((IDisposable)encryptionAlgorithm).Dispose();
            }
            return Convert.ToBase64String(iv);
        }
开发者ID:rockfordlhotka,项目名称:SerializationWrapper,代码行数:22,代码来源:CryptoWrapperBase.cs

示例15: GenerateSymmetricIv

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


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