Ejemplo n.º 1
0
        public static byte[] generateKey()
        {
            RandomNumberGenerator   rng = RNGCryptoServiceProvider.Create();
            SecureRandom            sr  = new SecureRandom();
            KeyGenerationParameters kgp = new KeyGenerationParameters(sr, DesEdeParameters.DesEdeKeyLength * 8);
            DesEdeKeyGenerator      kg  = new DesEdeKeyGenerator();

            byte[] key = new byte[16];

            kg.Init(kgp);
            var keyTmp = kg.GenerateKey();
            int len    = key.Length;

            DesEdeParameters.SetOddParity(keyTmp);

            /*
             * sbyte[] signedkey = new sbyte[key.Length];
             * int i = 0;
             * foreach (byte b in key)
             * {
             *  signedkey[i++] = unchecked((sbyte)b);
             * }
             */

            Array.Copy(keyTmp, 0, key, 0, 16);

            return(key);
        }
Ejemplo n.º 2
0
        protected override byte[] engineGenerateKey()
        {
            byte[] newKey = new byte[strength];

            do
            {
                random.NextBytes(newKey);
                DesEdeParameters.SetOddParity(newKey);
            }while (DesEdeParameters.IsWeakKey(newKey, 0, newKey.Length) || !DesEdeParameters.IsRealEdeKey(newKey, 0));

            return(newKey);
        }
Ejemplo n.º 3
0
        protected override byte[] engineGenerateKey()
        {
            byte[] newKey;

            do
            {
                newKey = random.GenerateSeed(strength);
                DesEdeParameters.SetOddParity(newKey);
            }while (DesEdeParameters.IsWeakKey(newKey, 0, newKey.Length));

            return(newKey);
        }
Ejemplo n.º 4
0
            public void Init(bool forEncryption, ICipherParameters parameters)
            {
                byte[] k = Arrays.Clone(((KeyParameter)parameters).GetKey());

                DesEdeParameters.SetOddParity(k);

                if (!Arrays.AreEqual(((KeyParameter)parameters).GetKey(), k))
                {
                    throw new ArgumentException("key not odd parity");
                }

                cipher.Init(forEncryption, parameters);
            }
        public static byte[] GenerateKey()
        {
            var secureRandom = new SecureRandom();
            var kgp          = new KeyGenerationParameters(secureRandom, DesEdeParameters.DesKeyLength * 16);
            var kg           = new DesEdeKeyGenerator();

            kg.Init(kgp);

            byte[] desKeyBytes = kg.GenerateKey();
            DesEdeParameters.SetOddParity(desKeyBytes);

            return(desKeyBytes);
        }
Ejemplo n.º 6
0
        public static byte[] generateKey()
        {
            RandomNumberGenerator   rng = RNGCryptoServiceProvider.Create();
            SecureRandom            sr  = new SecureRandom();
            KeyGenerationParameters kgp = new KeyGenerationParameters(sr, DesEdeParameters.DesEdeKeyLength * 8);
            DesEdeKeyGenerator      kg  = new DesEdeKeyGenerator();

            kg.Init(kgp);
            var key = kg.GenerateKey();
            int len = key.Length;

            DesEdeParameters.SetOddParity(key);
            return(key);
        }