using (Session session = slot.OpenSession(SessionType.ReadWrite))
{
session.Login(CKU.CKU_SO, "pin");
List<ObjectAttribute> publicKeyAttributes = new List<ObjectAttribute>();
publicKeyAttributes.Add(new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_SECRET_KEY));
publicKeyAttributes.Add(new ObjectAttribute(CKA.CKA_KEY_TYPE, CKK.CKK_RSA));
publicKeyAttributes.Add(new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_CERTIFICATE));
publicKeyAttributes.Add(new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_PRIVATE_KEY));
publicKeyAttributes.Add(new ObjectAttribute(CKA.CKA_LABEL, "label2"));
publicKeyAttributes.Add(new ObjectAttribute(CKA.CKA_LABEL, "label1"));
publicKeyAttributes.Add(new ObjectAttribute(CKA.CKA_LABEL, "Pkcs11Interop"));
List<ObjectHandle> foundPublicKeys = session.FindAllObjects(publicKeyAttributes);
}
I am trying to use the Pkcs11Interop library to get my own certificate from HSM and get it from the bill.
When I try to find my own certificate with this code:
var foundObjects = session.FindAllObjects (searchTemplate)
It returned zero (0).
session.GenerateKeyPair (mechanism, publicKeyAttributes, privateKeyAttributes, out publicKeyHandle, out privateKeyHandle);
I found this code but I get an error.
C_GenerateKeyPair returned CKR_USER_NOT_LOGGED_IN
Can anyone help me? Thanks.