System.Security.Cryptography.TripleDES.IsWeakKey C# (CSharp) Метод

IsWeakKey() публичный статический Метод

public static IsWeakKey ( byte rgbKey ) : bool
rgbKey byte
Результат bool
        public static bool IsWeakKey(byte[] rgbKey)
        {
            if (rgbKey == null)
                throw new CryptographicException(SR.Cryptography_InvalidKeySize);  // Desktop compat: Strange exception for a null value, but this is what we threw in classic CLR.

            if (!(rgbKey.Length*8).IsLegalSize(s_legalKeySizes))
                throw new CryptographicException(SR.Cryptography_InvalidKeySize);

            byte[] rgbOddParityKey = rgbKey.FixupKeyParity();
            if (EqualBytes(rgbOddParityKey, 0, 8, 8))
                return true;
            if ((rgbOddParityKey.Length == 24) && EqualBytes(rgbOddParityKey, 8, 16, 8))
                return true;
            return false;
        }

Usage Example

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