none
Force use to have a keyfile to run an application RRS feed

  • Question

  • I'm making an application but I want to force a user to have a keyfile locally on their system so that even if someone else were to get their hands on it, they wouldn't be able to use it unless this keyfile was present.
    Thursday, September 26, 2019 3:40 PM

All replies

  • Hi BeardsOrNoBeards, 

    Thank you for posting here.

    According to your description, you can convert key file to pfx file first.

    Is it possible to convert an SSL certificate from a .key file to a .pfx?

    Then ensure that someone else cannot run the application by verifying path of pfx file and passwords.

    Here’s the code:

            static void Main(string[] args)
            {
                Console.WriteLine("please enter the path of a pfx file");
                var certPath = Console.ReadLine();
                Console.WriteLine("please enter the password");
                var certPass = Console.ReadLine(); 
    
                X509Certificate2Collection collection = new X509Certificate2Collection();
                try
                {
                    collection.Import(certPath, certPass, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
                    Console.WriteLine("success");
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.ReadLine();
                    return;
                }
                Console.ReadLine();
            }

    Result of the test:

    Hope it can help you.

    Best Regards,

    Xingyu Zhao



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, September 27, 2019 3:28 AM
    Moderator