I'm trying to find public keys (certificates) with this code below but I can't collect those certificates.
using (Pkcs11 pkcs11 = new Pkcs11(@"\\ip\c$\Program Files\SafeNet\Protect Toolkit 5\Protect Toolkit C SDK\bin\sw\cryptoki.dll", AppType.MultiThreaded))
{
List<Slot> slots = pkcs11.GetSlotList(SlotsType.WithTokenPresent);
Slot slot = slots[0];
using (Session session = slot.OpenSession(SessionType.ReadOnly))
{
var sessionState = session.GetSessionInfo();
session.Login(CKU.CKU_USER, "password");
List<ObjectAttribute> publicKeyAttributes = new List<ObjectAttribute>();
publicKeyAttributes.Add(new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_CERTIFICATE));
publicKeyAttributes.Add(new ObjectAttribute(CKA.CKA_TOKEN, true));
publicKeyAttributes.Add(new ObjectAttribute(CKA.CKA_CERTIFICATE_TYPE, CKC.CKC_X_509));
List<ObjectHandle> foundPublicKeys = session.FindAllObjects(publicKeyAttributes);
}
}
I needed to get foundPublicKeys values but it returned zero (0).
You can see those certificates in picture below named ****_CER. What am I missing? Thanks.