如何使用Pkcs11库查找公钥?

时间:2018-04-02 13:16:56

标签: c# .net rsa hsm pkcs11interop

我正在尝试使用以下代码查找公钥(证书),但我无法收集这些证书。

       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的证书。我错过了什么?感谢。

 public keys (certificates) are showed with name blabla_CER

0 个答案:

没有答案