示例#1
0
        ///<summary>All outgoing data filters through here.</summary>
        override protected bool HandleOutgoing(ICopyable app_data, out ICopyable data)
        {
            if (!_active)
            {
                if (_closed == 1)
                {
                    throw new SendException(false, "SA closed, unable to send!");
                }
                UpdateSH(null, null);
                data = null;
                return(false);
            }

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

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

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

            data = new CopyList(PeerSecOverlord.Security, PeerSecOverlord.SecureData, sdm.ICPacket);
            return(true);
        }
示例#2
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 = Brunet.Util.MemBlock.Reference(data);
            sh.SignAndEncrypt(sdm);
            SecurityDataMessage sdm_d = new SecurityDataMessage(sdm.Packet);

            sh.DecryptAndVerify(sdm_d);
            Assert.AreEqual(sdm.Data, sdm.Data, "SecurityHandler");
        }