Exemplo n.º 1
0
        }   // End Constructor

        public string GenerateKey()
        {
            string retValue = null;

            using (System.Security.Cryptography.Aes aes = System.Security.Cryptography.Aes.Create())
            {
                aes.GenerateKey();
                aes.GenerateIV();

                byte[] bIV  = aes.IV;
                byte[] bKey = aes.Key;
                aes.Clear();

                retValue = "IV: " + ByteArrayToHexString(bIV)
                           + System.Environment.NewLine
                           + "Key: " + ByteArrayToHexString(bKey);

                System.Array.Clear(bIV, 0, bIV.Length);
                System.Array.Clear(bKey, 0, bKey.Length);
                bIV  = null;
                bKey = null;
            } // End Using aes

            return(retValue);
        } // End Function GenerateKey
Exemplo n.º 2
0
        static void KeyGenConsole()
        {
            Console.WriteLine("Which?");
            // Console.WriteLine("1. RSA");
            Console.WriteLine("2. AES");
            Console.Write("> ");
            string input = Console.ReadLine();

            switch (input)
            {
            case "1":
                // TODO
                break;

            case "2":
                System.Security.Cryptography.Aes aesAlg = System.Security.Cryptography.Aes.Create();
                aesAlg.GenerateKey();
                byte[] key = aesAlg.Key;
                Util.SaveFile.WriteFile("./AES.-2.key", key);
                aesAlg.GenerateKey();
                Util.SaveFile.WriteFile("./AES.-1.key", aesAlg.Key);
                break;
            }
        }
Exemplo n.º 3
0
        } // End Sub SetIV

        public static string GenerateKey()
        {
            byte[] bIV;
            byte[] bKey;

            using (System.Security.Cryptography.Aes aes = System.Security.Cryptography.Aes.Create())
            {
                aes.GenerateKey();
                aes.GenerateIV();

                bIV  = aes.IV;
                bKey = aes.Key;
                // aes.Clear();
            } // End Using aes

            return("IV: " + ByteArrayToHexString(bIV) + System.Environment.NewLine + "Key: " + ByteArrayToHexString(bKey));
        } // End Function GenerateKey