IsWeakKey() public static method

public static IsWeakKey ( byte rgbKey ) : bool
rgbKey byte
return bool
 public override ICryptoTransform CreateDecryptor(byte[] rgbKey, byte[] rgbIV)
 {
     if (TripleDES.IsWeakKey(rgbKey))
     {
         throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKey_Weak"), "TripleDES");
     }
     return(this._NewEncryptor(rgbKey, this.ModeValue, rgbIV, this.FeedbackSizeValue, CryptoAPITransformMode.Decrypt));
 }
 /// <summary>Generates a random <see cref="P:System.Security.Cryptography.SymmetricAlgorithm.Key" /> to be used for the algorithm.</summary>
 // Token: 0x060023D2 RID: 9170 RVA: 0x00082688 File Offset: 0x00080888
 public override void GenerateKey()
 {
     this.KeyValue = new byte[this.KeySizeValue / 8];
     Utils.StaticRandomNumberGenerator.GetBytes(this.KeyValue);
     while (TripleDES.IsWeakKey(this.KeyValue))
     {
         Utils.StaticRandomNumberGenerator.GetBytes(this.KeyValue);
     }
 }
示例#3
0
        static internal byte[] GetStrongKey()
        {
            int size = DESTransform.BLOCK_BYTE_SIZE * 3;

            byte[] key = KeyBuilder.Key(size);
            while (TripleDES.IsWeakKey(key))
            {
                key = KeyBuilder.Key(size);
            }
            return(key);
        }
 /// <include file='doc\TripleDESCryptoServiceProvider.uex' path='docs/doc[@for="TripleDESCryptoServiceProvider.GenerateKey"]/*' />
 public override void GenerateKey()
 {
     // respect KeySizeValue
     KeyValue = new byte[KeySizeValue / 8];
     RNG.GetBytes(KeyValue);
     // Never hand back a weak or semi-weak key
     while (TripleDES.IsWeakKey(KeyValue))
     {
         RNG.GetBytes(KeyValue);
     }
 }
        internal static byte[] GetStrongKey()
        {
            int size = DESTransform.BLOCK_BYTE_SIZE * 3;

            byte[] array = KeyBuilder.Key(size);
            while (TripleDES.IsWeakKey(array))
            {
                array = KeyBuilder.Key(size);
            }
            return(array);
        }
示例#6
0
        public TripleDESTransform(TripleDES algo, bool encryption, byte[] key, byte[] iv) : base(algo, encryption, iv)
        {
#if NET_2_0
            if (key == null)
            {
                key = GetStrongKey();
            }
#endif
            // note: checking weak keys also checks valid key length
            if (TripleDES.IsWeakKey(key))
            {
                string msg = Locale.GetText("This is a known weak key.");
                throw new CryptographicException(msg);
            }

            byte[] key1 = new byte [8];
            byte[] key2 = new byte [8];
            byte[] key3 = new byte [8];
            DES    des  = DES.Create();
            Buffer.BlockCopy(key, 0, key1, 0, 8);
            Buffer.BlockCopy(key, 8, key2, 0, 8);
            if (key.Length == 16)
            {
                Buffer.BlockCopy(key, 0, key3, 0, 8);
            }
            else
            {
                Buffer.BlockCopy(key, 16, key3, 0, 8);
            }

            // note: some modes (like CFB) requires encryption when decrypting
            if ((encryption) || (algo.Mode == CipherMode.CFB))
            {
                E1 = new DESTransform(des, true, key1, iv);
                D2 = new DESTransform(des, false, key2, iv);
                E3 = new DESTransform(des, true, key3, iv);
            }
            else
            {
                D1 = new DESTransform(des, false, key3, iv);
                E2 = new DESTransform(des, true, key2, iv);
                D3 = new DESTransform(des, false, key1, iv);
            }
        }
        public TripleDESTransform(TripleDES algo, bool encryption, byte[] key, byte[] iv) : base(algo, encryption, iv)
        {
            if (key == null)
            {
                key = TripleDESTransform.GetStrongKey();
            }
            if (TripleDES.IsWeakKey(key))
            {
                string text = Locale.GetText("This is a known weak key.");
                throw new CryptographicException(text);
            }
            byte[] array    = new byte[8];
            byte[] array2   = new byte[8];
            byte[] array3   = new byte[8];
            DES    symmAlgo = DES.Create();

            Buffer.BlockCopy(key, 0, array, 0, 8);
            Buffer.BlockCopy(key, 8, array2, 0, 8);
            if (key.Length == 16)
            {
                Buffer.BlockCopy(key, 0, array3, 0, 8);
            }
            else
            {
                Buffer.BlockCopy(key, 16, array3, 0, 8);
            }
            if (encryption || algo.Mode == CipherMode.CFB)
            {
                this.E1 = new DESTransform(symmAlgo, true, array, iv);
                this.D2 = new DESTransform(symmAlgo, false, array2, iv);
                this.E3 = new DESTransform(symmAlgo, true, array3, iv);
            }
            else
            {
                this.D1 = new DESTransform(symmAlgo, false, array3, iv);
                this.E2 = new DESTransform(symmAlgo, true, array2, iv);
                this.D3 = new DESTransform(symmAlgo, false, array, iv);
            }
        }
示例#8
0
 bool ICngSymmetricAlgorithm.IsWeakKey(byte[] key)
 {
     return(TripleDES.IsWeakKey(key));
 }