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


C# SymmetricAlgorithm.ValidKeySize方法代码示例

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


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

示例1: InitSymmetric

        public static SymmetricAlgorithm InitSymmetric(SymmetricAlgorithm algorithm, string password, int key_bit_length)
        {
            var salt = new byte[] { 1, 2, 23, 234, 37, 48, 134, 63, 248, 4 };

            const int iterations = 234;
            using (var rfc2898_derive_bytes = new Rfc2898DeriveBytes(password, salt, iterations))
            {
                if (!algorithm.ValidKeySize(key_bit_length))
                    throw new InvalidOperationException("Invalid size key");

                algorithm.Key = rfc2898_derive_bytes.GetBytes(key_bit_length / 8);
                algorithm.IV = rfc2898_derive_bytes.GetBytes(algorithm.BlockSize / 8);
                return algorithm;
            }
        }
开发者ID:spenny2012,项目名称:UserInfo,代码行数:15,代码来源:CreateOther.cs

示例2: InitSymmetric

        private static SymmetricAlgorithm InitSymmetric(SymmetricAlgorithm algorithm, SecureString password, int keyBitLength, byte[] salt)
        {
            const int Iterations = 1000;

            using (var secureStringBytes = new SecureStringBytes(password))
            {
                using (var rfc2898DeriveBytes = new Rfc2898DeriveBytes(secureStringBytes.GetBytes(), salt, Iterations))
                {
                    if (!algorithm.ValidKeySize(keyBitLength))
                    {
                        throw new InvalidOperationException("Invalid size key");
                    }

                    algorithm.Key = rfc2898DeriveBytes.GetBytes(keyBitLength / 8);
                    algorithm.IV = rfc2898DeriveBytes.GetBytes(algorithm.BlockSize / 8);
                    return algorithm;
                }
            }
        }
开发者ID:helgihaf,项目名称:Alpha,代码行数:19,代码来源:VaultSecurity.cs

示例3: GetStartingKeyAndIVForEncryption

		private Tuple<byte[], byte[]> GetStartingKeyAndIVForEncryption(SymmetricAlgorithm algorithm)
		{
			int bits = algorithm.ValidKeySize(EncryptionSettings.PreferedEncryptionKeyBitsSize) ? 
				EncryptionSettings.PreferedEncryptionKeyBitsSize :
				algorithm.LegalKeySizes[0].MaxSize;
			
			encryptionKeySize = bits / 8;
			encryptionIVSize = algorithm.IV.Length;

			var deriveBytes = new Rfc2898DeriveBytes(EncryptionSettings.EncryptionKey, GetSaltFromEncryptionKey(EncryptionSettings.EncryptionKey), Constants.Rfc2898Iterations);
			return Tuple.Create(deriveBytes.GetBytes(encryptionKeySize.Value), deriveBytes.GetBytes(encryptionIVSize.Value));
		}
开发者ID:925coder,项目名称:ravendb,代码行数:12,代码来源:Codec.cs


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