System.Security.Cryptography.TripleDESTransform.GetStrongKey C# (CSharp) Method

GetStrongKey() static private method

static private GetStrongKey ( ) : byte[]
return byte[]
		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;
		}
	}

Usage Example

        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);
            }
        }
All Usage Examples Of System.Security.Cryptography.TripleDESTransform::GetStrongKey