Using the answer @jariq posted for C# I was able to get the following to work in PowerShell
for changing the Admin PIN
.
Note: this is specifically for Gemalto IDPrime .NET cards which are being replaced by the IDPrime MD product line. See the end of this post for more info.
# www.pkcs11interop.net
Add-Type -Path "C:\Somepath\Pkcs11Interop.4.0.0\lib\net45\Pkcs11Interop.dll"
# Gemalto PKCS11 driver
# 1 = single threaded
$pkcs11 = New-Object Net.Pkcs11Interop.HighLevelAPI.Pkcs11("C:\somepath\gtop11dotnet64.dll",1)
# 0 = SlotsType.WithTokenPresent
$slots = $pkcs11.GetSlotList(0)
$slot = $slots[0] # often its the first
# create session
# 1 = SessionType.ReadWrite
$session = $slot.OpenSession(1)
[byte[]]$defaultPIN = 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
# 000000000000000000000001
[byte[]]$newPIN = 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31
# 0 = Security Officer a.k.a. Admin
$session.Login(0, $defaultPIN)
$session.SetPin($defaultPIN, $newPIN)
$session.Dispose()
$slot.CloseAllSessions()
$pkcs11.Dispose()
I found the most success converting each PIN
to a byte array for use with logging in and changing the PIN
. To convert the 48 digit Admin PIN to 24 bytes, the following function was created.
Function Convert-AdminPinToByteArray([Validatepattern("^[0-9A-F]{48}$")][string]$AdminPIN)
{
$ReturnByte = New-Object byte[] 24
$n = 0
for($i=0;$i -lt $ReturnByte.Length;$i++)
{
$ReturnByte[$i] = [byte]"0x$($AdminPIN.SubString($n,2))"
$n = $n + 2
}
return $ReturnByte
} # End Function Convert-AdminPinToByteArray
Gemalto Card Types
The above examples are based off Gemalto IDPrime .NET cards which are being retired. The End of Sale (EOS) announcement is here.
IDPrime .Net
IDPrime .Net Bio
Key Dates:
Milestone Date
Last-Time-Buy (LTB) September 29, 2017
End-of-Sale (EOS) September 30, 2017
End-of-Life (EOL) September 30, 2018
Replacement
Per the EOS announcement PDF:
Products Gemalto’s family of IDPrime .NET 510/511 smart cards will be replaced by the IDPrime MD 83x and IDPrime MD 84x series of smart cards.
Programming the Replacement cards
I've included the information about distinguishing card types because I have a Gemalto IDPrime MD 830 for testing and the above techniques do not work. In fact, the card doesn't even show as being present in the reader using the above techniques.