コード例 #1
0
ファイル: GarlicTest.cs プロジェクト: itfenom/i2p-cs
        public void TestGarlicCreate()
        {
            var ls = new I2PDate(DateTime.Now + TimeSpan.FromMinutes(5));

            var origmessage = new DeliveryStatusMessage(I2NPMessage.GenerateMessageId());
            var bigmessage  = new DataMessage(new BufLen(BufUtils.RandomBytes(14 * 1024)));

            var garlic = new Garlic(
                new GarlicClove(
                    new GarlicCloveDeliveryLocal(origmessage),
                    ls),
                new GarlicClove(
                    new GarlicCloveDeliveryLocal(bigmessage),
                    ls)
                );

            var egmsg = Garlic.EGEncryptGarlic(
                garlic,
                Public,
                new I2PSessionKey(),
                null);

            var origegdata  = I2NPMessage.Clone(egmsg);
            var origegdata2 = I2NPMessage.Clone(egmsg);

            // Decrypt

            var(aesblock, sessionkey1) = Garlic.EGDecryptGarlic(origegdata, Private);

            var newgarlic = new Garlic((BufRefLen)aesblock.Payload);

            var g1 = new BufLen(garlic.ToByteArray());
            var g2 = new BufLen(newgarlic.ToByteArray());

            Assert.IsTrue(g1 == g2);

            // Retrieve

            var(aesblock2, sessionkey2) = Garlic.RetrieveAESBlock(origegdata2, Private, null);

            newgarlic = new Garlic((BufRefLen)aesblock2.Payload);

            g1 = new BufLen(garlic.ToByteArray());
            g2 = new BufLen(newgarlic.ToByteArray());

            Assert.IsTrue(g1 == g2);
            Assert.IsTrue(sessionkey1 == sessionkey2);
        }
コード例 #2
0
ファイル: GarlicTest.cs プロジェクト: itfenom/i2p-cs
        public void TestEncodeDecodeAES()
        {
            var m1 = new DeliveryStatusMessage(0x4321);
            var m2 = new DeliveryStatusMessage(0xa3c2);

            var garlic = new Garlic(
                new GarlicClove(
                    new GarlicCloveDeliveryDestination(
                        m1,
                        Destination.IdentHash)),
                new GarlicClove(
                    new GarlicCloveDeliveryDestination(
                        m2,
                        Destination.IdentHash))
                );

            // No tags

            var sessionkey = new I2PSessionKey();
            var sessiontag = new I2PSessionTag();

            var cg     = Garlic.AESEncryptGarlic(garlic, sessionkey, sessiontag, null);
            var egdata = I2NPMessage.Clone(cg);

            var(aesblock, sk) = Garlic.RetrieveAESBlock(egdata, Private, (t) => sessionkey);
            var g2 = new Garlic((BufRefLen)aesblock.Payload);

            Assert.IsTrue(BufUtils.Equal(garlic.ToByteArray(), g2.ToByteArray()));

            // With tags
            var tags = new List <I2PSessionTag>();

            for (int i = 0; i < 30; ++i)
            {
                tags.Add(new I2PSessionTag());
            }

            cg     = Garlic.AESEncryptGarlic(garlic, sessionkey, sessiontag, null);
            egdata = I2NPMessage.Clone(cg);

            (aesblock, sk) = Garlic.RetrieveAESBlock(egdata, Private, (t) => sessionkey);
            g2             = new Garlic((BufRefLen)aesblock.Payload);

            Assert.IsTrue(BufUtils.Equal(garlic.ToByteArray(), g2.ToByteArray()));
        }