Exemplo n.º 1
0
        static void RunSnippet(string[] args)
        {
            // DevTest.JSON.JSONTester.LoadFromFile();


            //EventEmitterTest.Combine();
            return;

            SymmetricAlgorithmTest.Test();
            return;


            var text = "encode text valuefasdfasdfasdfaewe53253";
            var key  = "testkey123456789";
            // TExuOaf8aXJsfZE6ojWJZXKiS0jQri8/iNIj/4omWRB4Jurkm7mG7eljT94=
            var result = Epic.Security.Cryptography.XXTEA.Encrypt(Encoding.UTF8.GetBytes(key), Encoding.UTF8.GetBytes(text));

            WL(result.Length);
            WL(Convert.ToBase64String(result));

            var result1 = Epic.Security.Cryptography.XXTEA2.Test(text);

            WL(Convert.ToBase64String(result1));
            //SymmetricAlgorithmTest.Test();
        }
Exemplo n.º 2
0
        public static void Test()
        {
            ECDiffieHellmanCng alice = new ECDiffieHellmanCng();

            alice.KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hash;
            alice.HashAlgorithm         = CngAlgorithm.Sha1;


            ECDiffieHellmanCng bob = new ECDiffieHellmanCng();

            bob.KeyDerivationFunction = ECDiffieHellmanKeyDerivationFunction.Hash;
            bob.HashAlgorithm         = CngAlgorithm.Sha1;



            byte[] aliceKey = alice.DeriveKeyMaterial(bob.PublicKey);
            byte[] bobKey   = bob.DeriveKeyMaterial(alice.PublicKey);


            Console.WriteLine(bobKey.SequenceEqual(aliceKey));

            var r = new RijndaelManaged();

            r.GenerateIV();
            var iv = r.IV;

            byte[] encrypted = SymmetricAlgorithmTest.Encrypt <RijndaelManaged>(original, bobKey, iv);
            string roundtrip = SymmetricAlgorithmTest.Decrypt <RijndaelManaged>(encrypted, aliceKey, iv);
            string hex       = Epic.Converters.HexString.Encode(encrypted);
            string base64    = Convert.ToBase64String(encrypted);

            //Display the original data and the decrypted data.
            Console.WriteLine($"ECC:");
            Console.WriteLine("Byte:   {0}", encrypted.Length);
            Console.WriteLine("Hex:   {0}, {1}", hex.Length, hex);
            Console.WriteLine("Base64:   {0}, {1}", base64.Length, base64);
            Console.WriteLine("Decode: {0}", roundtrip);
            Console.WriteLine();
        }