我正在尝试使用Pkcs11Interop从HSM中提取密钥值。我知道,钥匙必须留在HSM里,但我需要它,所以...
我已经用NCryptoki这样做了,我也想用Pkcs11Interop这样做
我试过这段代码:
// Prepare attribute template that defines search criteria
List<ObjectAttribute> objectAttributes = new List<ObjectAttribute>();
objectAttributes.Add(new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_SECRET_KEY));
objectAttributes.Add(new ObjectAttribute(CKA.CKA_KEY_TYPE, CKK.CKK_DES));
objectAttributes.Add(new ObjectAttribute(CKA.CKA_LABEL, "MY_KEY"));
// Find all objects that match provided attributes
List<ObjectHandle> foundObjects = session.FindAllObjects(objectAttributes);
var key = foundObjects[0];
byte[] plainKeyValue = null;
List<ObjectAttribute> readAttrs = session.GetAttributeValue(key, new List<CKA>() { CKA.CKA_VALUE });
if (readAttrs[0].CannotBeRead)
throw new Exception("Key cannot be exported");
else
plainKeyValue = readAttrs[0].GetValueAsByteArray();但是plainKeyValue是全零的,但是,正如您可以想象的那样,这不是真的。
那么,我怎样才能达到我的目标呢?
https://stackoverflow.com/questions/47569311
复制相似问题