我正在尝试使用以下代码查找公钥(证书),但我无法收集这些证书。
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);
}
}
我需要获取foundPublicKeys值,但它返回零(0)。
您可以在下面的图片中看到名为**** _ CER的证书。我错过了什么?感谢。