IsWeakKey() 공개 정적인 메소드

public static IsWeakKey ( byte rgbKey ) : bool
rgbKey byte
리턴 bool
예제 #1
0
/*		static DESTransform ()
 *              {
 *                      spBoxes = new uint [64 * 8];
 *
 *                      int [] pBox = new int [32];
 *
 *                      for (int p = 0; p < 32; p++) {
 *                              for (int i = 0; i < 32; i++) {
 *                                      if (p == pTab [i]) {
 *                                              pBox [p] = i;
 *                                              break;
 *                                      }
 *                              }
 *                      }
 *
 *                      for (int s = 0; s < 8; s++) { // for each S-box
 *                              int sOff = s << 6;
 *
 *                              for (int i = 0; i < 64; i++) { // inputs
 *                                      uint sp=0;
 *
 *                                      int indx = (i & 0x20) | ((i & 1) << 4) | ((i >> 1) & 0xF);
 *
 *                                      for (int j = 0; j < 4; j++) { // for each bit in the output
 *                                              if ((sBoxes [sOff + indx] & (8 >> j)) != 0) {
 *                                                      sp |= (uint) (1 << (31 - pBox [(s << 2) + j]));
 *                                              }
 *                                      }
 *
 *                                      spBoxes [sOff + i] = sp;
 *                              }
 *                      }
 *
 *                      leftRotTotal = new byte [leftRot.Length];
 *
 *                      for (int i = 0; i < leftRot.Length; i++) {
 *                              int r = 0;
 *                              for (int j = 0; j <= i; r += leftRot [j++]) {
 *                                      // no statement (confuse the compiler == warning)
 *                              }
 *                              leftRotTotal [i]  = (byte) r;
 *                      }
 *
 *                      InitPermutationTable (ipBits, out ipTab);
 *                      InitPermutationTable (fpBits, out fpTab);
 *              }
 */
        // Default constructor.
        internal DESTransform(SymmetricAlgorithm symmAlgo, bool encryption, byte[] key, byte[] iv)
            : base(symmAlgo, encryption, iv)
        {
            byte[] clonedKey = null;
#if NET_2_0
            if (key == null)
            {
                key       = GetStrongKey();
                clonedKey = key;                 // no need to clone
            }
#endif
            // note: checking (semi-)weak keys also checks valid key length
            if (DES.IsWeakKey(key) || DES.IsSemiWeakKey(key))
            {
                string msg = Locale.GetText("This is a known weak, or semi-weak, key.");
                throw new CryptographicException(msg);
            }

            if (clonedKey == null)
            {
                clonedKey = (byte[])key.Clone();
            }

            keySchedule = new byte [KEY_BYTE_SIZE * 16];
            byteBuff    = new byte [BLOCK_BYTE_SIZE];
            dwordBuff   = new uint [BLOCK_BYTE_SIZE / 4];
            SetKey(clonedKey);
        }
 public override void GenerateKey()
 {
     base.KeyValue = new byte[8];
     Utils.StaticRandomNumberGenerator.GetBytes(base.KeyValue);
     while (DES.IsWeakKey(base.KeyValue) || DES.IsSemiWeakKey(base.KeyValue))
     {
         Utils.StaticRandomNumberGenerator.GetBytes(base.KeyValue);
     }
 }
예제 #3
0
 static internal byte[] GetStrongKey()
 {
     byte[] key = KeyBuilder.Key(DESTransform.KEY_BYTE_SIZE);
     while (DES.IsWeakKey(key) || DES.IsSemiWeakKey(key))
     {
         key = KeyBuilder.Key(DESTransform.KEY_BYTE_SIZE);
     }
     return(key);
 }
예제 #4
0
 internal static byte[] GetStrongKey()
 {
     byte[] array = KeyBuilder.Key(DESTransform.KEY_BYTE_SIZE);
     while (DES.IsWeakKey(array) || DES.IsSemiWeakKey(array))
     {
         array = KeyBuilder.Key(DESTransform.KEY_BYTE_SIZE);
     }
     return(array);
 }
        //    public SymmetricStreamDecryptor CreateDecryptor(DeriveBytesFromHash);

        /// <include file='doc\DESCryptoServiceProvider.uex' path='docs/doc[@for="DESCryptoServiceProvider.GenerateKey"]/*' />

        public override void GenerateKey()
        {
            KeyValue = new byte[8];
            RNG.GetBytes(KeyValue);
            // Never hand back a weak or semi-weak key
            while (DES.IsWeakKey(KeyValue) || DES.IsSemiWeakKey(KeyValue))
            {
                RNG.GetBytes(KeyValue);
            }
        }
 public override ICryptoTransform CreateEncryptor(byte[] rgbKey, byte[] rgbIV)
 {
     if (DES.IsWeakKey(rgbKey))
     {
         throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKey_Weak"), "DES");
     }
     if (DES.IsSemiWeakKey(rgbKey))
     {
         throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKey_SemiWeak"), "DES");
     }
     return(this._NewEncryptor(rgbKey, base.ModeValue, rgbIV, base.FeedbackSizeValue, CryptoAPITransformMode.Encrypt));
 }
예제 #7
0
 internal DESTransform(SymmetricAlgorithm symmAlgo, bool encryption, byte[] key, byte[] iv) : base(symmAlgo, encryption, iv)
 {
     byte[] array = null;
     if (key == null)
     {
         key   = DESTransform.GetStrongKey();
         array = key;
     }
     if (DES.IsWeakKey(key) || DES.IsSemiWeakKey(key))
     {
         string text = Locale.GetText("This is a known weak, or semi-weak, key.");
         throw new CryptographicException(text);
     }
     if (array == null)
     {
         array = (byte[])key.Clone();
     }
     this.keySchedule = new byte[DESTransform.KEY_BYTE_SIZE * 16];
     this.byteBuff    = new byte[DESTransform.BLOCK_BYTE_SIZE];
     this.dwordBuff   = new uint[DESTransform.BLOCK_BYTE_SIZE / 4];
     this.SetKey(array);
 }