Ejemplo n.º 1
0
        public int Execute()
        {
            if (string.IsNullOrEmpty(Name))
            {
                WriteHelp(Console.Error);
                return(1);
            }

            CngKey key;
            var    finder = new KeyFinder();

            try
            {
                if (finder.Find(Name, out key))
                {
                    key.Delete();
                    Console.WriteLine("Key " + Name + " deleted successfully");
                }

                else
                {
                    return(2);
                }

                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(3);
            }
            finally
            {
                finder.Dispose();
            }
        }
Ejemplo n.º 2
0
        public int Execute()
        {
            if (!Options.Valid)
            {
                WriteHelp(Console.Out);
                return 1;
            }

            try
            {
                CngKey key;
                var finder = new KeyFinder();
                if(string.IsNullOrEmpty(Options.Anything))
                {
                    if (finder.Find(Options.Name, Options.UniqueId, out key))
                    {
                        Console.WriteLine("Found key " + Options.Name ?? Options.UniqueId);
                        Console.WriteLine("\t algorithm: " + key.Algorithm);
                        Console.WriteLine("\t keysize: " + key.KeySize);
                        Console.WriteLine("\t usages: " + key.KeyUsage);
                        Console.WriteLine("\t uniquename: " + key.UniqueName);
                    }
                }
                else if (finder.Find(Options.Anything, out key))
                {
                    Console.WriteLine("Found key " + Options.Name ?? Options.UniqueId);
                    Console.WriteLine("\t algorithm: " + key.Algorithm);
                    Console.WriteLine("\t keysize: " + key.KeySize);
                    Console.WriteLine("\t usages: " + key.KeyUsage);
                    Console.WriteLine("\t uniquename: " + key.UniqueName);
                }

                return 2;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return 3;
            }
        }