Example #1
0
        private void EncryptDecrypt(string algorithm, int keySize, byte[] input)
        {
            byte[] key;
            byte[] IV;

            EncryptionConfig.GenKeyIV(algorithm, keySize, out key, out IV);

            BlockEncryptor encryptor = new BlockEncryptor(algorithm, key, IV);
            BlockDecryptor decryptor = new BlockDecryptor(algorithm, key, IV);

            byte[] encrypted;
            byte[] decrypted;
            bool   equal;

            encrypted = encryptor.Encrypt(input);

            if (algorithm.ToUpper() == CryptoAlgorithm.PlainText)
            {
                // Make sure the input/output buffers are identical.

                CollectionAssert.AreEqual(input, encrypted);
            }
            else
            {
                // Make sure the input/output buffers differ.

                if (input.Length > 0 && input.Length == encrypted.Length)
                {
                    equal = true;
                    for (int i = 0; i < input.Length; i++)
                    {
                        if (input[i] != encrypted[i])
                        {
                            equal = false;
                            break;
                        }
                    }

                    Assert.IsFalse(equal);
                }
            }

            decrypted = decryptor.Decrypt(encrypted);

            // Make sure we're back to the original bytes.

            CollectionAssert.AreEqual(input, decrypted);
        }
Example #2
0
        public void StartRouters(bool encrypt)
        {
            string encryption;

            byte[] key;
            byte[] IV;

            if (encrypt)
            {
                encryption = CryptoAlgorithm.TripleDES;
                EncryptionConfig.GenKeyIV(encryption, 128, out key, out IV);
            }
            else
            {
                encryption = CryptoAlgorithm.PlainText;
                key        = new byte[1];
                IV         = new byte[1];
            }

            Msg.ClearTypes();
            Msg.LoadTypes(Assembly.GetExecutingAssembly());

            g1r1 = new _SyncRouter("g1r1", group1, new IPEndPoint(IPAddress.Any, 5550), new IPEndPoint(IPAddress.Any, 5560),
                                   encryption, key, IV);
            g1r2 = new _SyncRouter("g1r2", group1, new IPEndPoint(IPAddress.Any, 5551), new IPEndPoint(IPAddress.Any, 5561),
                                   encryption, key, IV);
            g1r3 = new _SyncRouter("g1r3", group1, new IPEndPoint(IPAddress.Any, 5552), new IPEndPoint(IPAddress.Any, 5562),
                                   encryption, key, IV);
            g2r1 = new _SyncRouter("g2r1", group2, new IPEndPoint(IPAddress.Any, 5553), new IPEndPoint(IPAddress.Any, 5563),
                                   encryption, key, IV);
            g2r2 = new _SyncRouter("g2r2", group2, new IPEndPoint(IPAddress.Any, 5554), new IPEndPoint(IPAddress.Any, 5564),
                                   encryption, key, IV);

            g1r1.Start();
            g1r2.Start();
            g1r3.Start();
            g2r1.Start();
            g2r2.Start();
        }