Пример #1
0
        public void TDES()
        {
            SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
            SymmetricAlgorithm        sa   = new TripleDESCryptoServiceProvider();
            SecurityHandler           sh   = new SecurityHandler(sa, sa, sha1, sha1, 0);

            byte[] data = new byte[1024];
            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();

            rng.GetBytes(data);
            SecurityDataMessage sdm = new SecurityDataMessage();

            sdm.SPI  = 5;
            sdm.Data = MemBlock.Reference(data);
            sh.SignAndEncrypt(sdm);
            SecurityDataMessage sdm_d = new SecurityDataMessage(sdm.Packet);

            sh.DecryptAndVerify(sdm_d);
            Assert.AreEqual(sdm.Data, sdm.Data, "SecurityHandler");
        }
Пример #2
0
        ///<summary>All outgoing data filters through here.</summary>
        public void Send(ICopyable data)
        {
            if (!_active)
            {
                if (_closed == 1)
                {
                    throw new SendException(false, "SA closed, unable to send!");
                }
                UpdateSH(null, null);
                return;
            }

            // prepare the packet
            SecurityDataMessage sdm = new SecurityDataMessage();

            sdm.SPI  = _spi;
            sdm.Data = data as MemBlock;
            if (sdm.Data == null)
            {
                byte[] b = new byte[data.Length];
                data.CopyTo(b, 0);
                sdm.Data = MemBlock.Reference(b);
            }

            // Encrypt it!
            lock (_sync) {
                _current_sh.SignAndEncrypt(sdm);
            }

            // Prepare for sending and send over the underlying ISender!
            data = new CopyList(SecurityOverlord.Security, SecurityOverlord.SecureData, sdm.ICPacket);
            try {
                _sender.Send(data);
                _running = true;
            } catch (Exception e) {
                Close("Failed on sending");
                throw new SendException(false, "Failed on sending closing...", e);
            }
        }