예제 #1
0
 internal static 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);
 }
예제 #2
0
        private int j;                 // Key indexer

        public RC2Transform(RC2 rc2Algo, bool encryption, byte[] key, byte[] iv)
            : base(rc2Algo, encryption, iv)
        {
            int t1 = rc2Algo.EffectiveKeySize;

            if (key == null)
            {
                key = KeyBuilder.Key(rc2Algo.KeySize >> 3);
            }
            else
            {
                key = (byte[])key.Clone();
                t1  = Math.Min(t1, key.Length << 3);
            }

            int t = key.Length;

            if (!KeySizes.IsLegalKeySize(rc2Algo.LegalKeySizes, (t << 3)))
            {
                string msg = Locale.GetText("Key is too small ({0} bytes), it should be between {1} and {2} bytes long.", t, 5, 16);
                throw new CryptographicException(msg);
            }

            // Expand key into a byte array, then convert to word
            // array since we always access the key in 16bit chunks.
            byte[] L = new byte[128];

            int t8 = ((t1 + 7) >> 3);             // divide by 8
            int tm = 255 % (2 << (8 + t1 - (t8 << 3) - 1));

            for (int i = 0; i < t; i++)
            {
                L[i] = key[i];
            }
            for (int i = t; i < 128; i++)
            {
                L[i] = (byte)(pitable[(L[i - 1] + L[i - t]) & 0xff]);
            }

            L[128 - t8] = pitable[L[128 - t8] & tm];

            for (int i = 127 - t8; i >= 0; i--)
            {
                L[i] = pitable[L[i + 1] ^ L[i + t8]];
            }

            K = new UInt16[64];
            int pos = 0;

            for (int i = 0; i < 64; i++)
            {
                K[i] = (UInt16)(L[pos++] + (L[pos++] << 8));
            }
        }
예제 #3
0
        internal static byte[] GetStrongKey()
        {
            int size = DESTransform.BLOCK_BYTE_SIZE * 3;

            byte[] key = KeyBuilder.Key(size);
            while (TripleDES.IsWeakKey(key))
            {
                key = KeyBuilder.Key(size);
            }
            return(key);
        }
        public Rfc2898DeriveBytes(string password, int saltSize, int iterations)
        {
            if (password == null)
            {
                throw new ArgumentNullException("password");
            }
            if (saltSize < 0)
            {
                throw new ArgumentOutOfRangeException("invalid salt length");
            }

            Salt           = KeyBuilder.Key(saltSize);
            IterationCount = iterations;
            _hmac          = new HMACSHA1(Encoding.UTF8.GetBytes(password));
        }
 public override void GenerateKey()
 {
     KeyValue = KeyBuilder.Key(KeySizeValue >> 3);
 }
예제 #6
0
 public HMACSHA1()
     : this(KeyBuilder.Key(8))
 {
 }
예제 #7
0
 public HMACMD5()
     : this(KeyBuilder.Key(8))
 {
 }