smartcardgemalto

Change PIN of a Gemalto Smartcard through a script


We have to use the Gemalto IDPrime .Net card Smartcard. We get these USB Dongles and have to change the PIN.

Gemalto says via windows:

From the Start menu, choose Run and type PINTool.
Insert a IDPrime .Net card in the reader as prompted, and click OK. The change PIN interface appears
Enter the old PIN (the default PIN value is 0000), the new PIN and confirm the new PIN.
Click on Change Pin

http://support.gemalto.com/index.php?id=how_to_change_pin_in_a_idprime#.VWYTWUa8rV8

This works, but I want to set a new PIN/password via powershell or c#, i. e. under control of a program. How to do that or is impossible?


Solution

  • You should be able to change PIN via unmanaged PKCS#11 API that can be easily accessed from C# with a managed .NET wrapper called Pkcs11Interop which I am the author of.

    Here is the code sample that may help you get started:

    using Net.Pkcs11Interop.Common;
    using Net.Pkcs11Interop.HighLevelAPI;
    
    namespace ConsoleApplication
    {
        class Program
        {
            static void Main(string[] args)
            {
                // Load PKCS#11 library provided by Gemalto
                using (Pkcs11 pkcs11 = new Pkcs11("gtop11dotnet.dll", true))
                {
                    // Find first slot/reader with token/card present
                    Slot slot = pkcs11.GetSlotList(true)[0];
    
                    // Open RW session
                    using (Session session = slot.OpenSession(false))
                    {
                        // Login as normal user with current PIN
                        session.Login(CKU.CKU_USER, "0000");
    
                        // Set the new pin for the logged in user
                        session.SetPin("0000", "1111");
    
                        session.Logout();
                    }
                }
            }
        }
    }