NServiceBus.RijndaelEncryptionService.IsValidKey C# (CSharp) Method

IsValidKey() static private method

static private IsValidKey ( byte key ) : bool
key byte
return bool
        static bool IsValidKey(byte[] key)
        {
            using (var rijndael = new RijndaelManaged())
            {
                var bitLength = key.Length*8;

                var maxValidKeyBitLength = rijndael.LegalKeySizes.Max(keyLength => keyLength.MaxSize);
                if (bitLength < maxValidKeyBitLength)
                {
                    Log.WarnFormat("Encryption key is {0} bits which is less than the maximum allowed {1} bits. Consider using a {1}-bit encryption key to obtain the maximum cipher strength", bitLength, maxValidKeyBitLength);
                }

                return rijndael.ValidKeySize(bitLength);
            }
        }