Beispiel #1
0
        // https://csharp.hotexamples.com/examples/Org.BouncyCastle.Crypto.Macs/Poly1305/BlockUpdate/php-poly1305-blockupdate-method-examples.html
        public static void Poly1305AES()
        {
            Org.BouncyCastle.Crypto.IMac mac = new Org.BouncyCastle.Crypto.Macs.Poly1305(new Org.BouncyCastle.Crypto.Engines.AesEngine());
            byte[] key = null;
            byte[] n   = new byte[16];

            byte[] input  = System.Text.Encoding.UTF8.GetBytes("Hello World!");
            byte[] output = new byte[mac.GetMacSize()];

            for (int loop = 0; loop < 13; loop++)
            {
                mac.Init(new Org.BouncyCastle.Crypto.Parameters.ParametersWithIV(new Org.BouncyCastle.Crypto.Parameters.KeyParameter(key), n));
                mac.BlockUpdate(input, 0, input.Length);
                mac.DoFinal(output, 0);
            }
        }
Beispiel #2
0
        private void Poly1305CheckHash(byte[] keyMaterial, byte[] input, byte[] tag)
        {
            Org.BouncyCastle.Crypto.Macs.Poly1305 poly1305 = new Org.BouncyCastle.Crypto.Macs.Poly1305();
            poly1305.Init(new Org.BouncyCastle.Crypto.Parameters.KeyParameter(keyMaterial));

            poly1305.BlockUpdate(input, 0, input.Length);

            byte[] mac = new byte[poly1305.GetMacSize()];

            poly1305.DoFinal(mac, 0);

            if (!Org.BouncyCastle.Utilities.Arrays.AreEqual(tag, mac))
            {
                System.Console.WriteLine("fail");
                // Fail("rfc7539", Org.BouncyCastle.Utilities.Encoders.Hex.ToHexString(tag), Org.BouncyCastle.Utilities.Encoders.Hex.ToHexString(mac));
            }
        }
Beispiel #3
0
        } // End Function Sha3

        // https://www.programcreek.com/java-api-examples/index.php?api=org.bouncycastle.crypto.engines.SerpentEngine
        // https://stackoverflow.com/questions/9806012/multiple-encryption-with-bouncycastle
        public static void Poly1305Tests()
        {
            // https://www.programcreek.com/java-api-examples/index.php?api=org.bouncycastle.crypto.engines.TwofishEngine
            var poly = new Org.BouncyCastle.Crypto.Macs.Poly1305(new Org.BouncyCastle.Crypto.Engines.SerpentEngine());

            poly.Init(null);


            var se   = new Org.BouncyCastle.Crypto.Engines.Salsa20Engine();
            var pwiv = new Org.BouncyCastle.Crypto.Parameters.ParametersWithIV(
                new Org.BouncyCastle.Crypto.Parameters.KeyParameter(new byte[16])
                , new byte[8]
                );


            // https://en.wikipedia.org/wiki/Salsa20
            var xse   = new Org.BouncyCastle.Crypto.Engines.XSalsa20Engine();
            var xsekp = new Org.BouncyCastle.Crypto.Parameters.ParametersWithIV(
                new Org.BouncyCastle.Crypto.Parameters.KeyParameter(new byte[32])
                , new byte[24]
                );


            var engine = new Org.BouncyCastle.Crypto.Engines.RC4Engine();

            byte[] key = System.Text.Encoding.UTF8.GetBytes("foobar");
            engine.Init(true, new Org.BouncyCastle.Crypto.Parameters.KeyParameter(key));


            Org.BouncyCastle.Crypto.Engines.TwofishEngine twofish = new Org.BouncyCastle.Crypto.Engines.TwofishEngine();
            twofish.Init(true, new Org.BouncyCastle.Crypto.Parameters.KeyParameter(key));
            new Org.BouncyCastle.Crypto.Engines.ThreefishEngine(1024);

            Org.BouncyCastle.Crypto.BufferedBlockCipher cipher =
                new Org.BouncyCastle.Crypto.BufferedBlockCipher(new Org.BouncyCastle.Crypto.Engines.TwofishEngine());
        }