问题描述
我已经使用 Pkcs11 生成了 DES2 密钥,现在我需要从 HSM 中检索密钥校验和值。
我的代码
public void checkValue(ISession session,String label)
{
List<IObjectAttribute> objectAttributes = new List<IObjectAttribute>();
objectAttributes.Add(session.Factories.ObjectAttributeFactory.Create(CKA.CKA_CLASS,CKO.CKO_SECRET_KEY));
objectAttributes.Add(session.Factories.ObjectAttributeFactory.Create(CKA.CKA_KEY_TYPE,CKK.CKK_DES2));
objectAttributes.Add(session.Factories.ObjectAttributeFactory.Create(CKA.CKA_LABEL,label));
List<IObjectHandle> foundobjects = session.FindAllObjects(objectAttributes);
var key = foundobjects[0];
List<IObjectAttribute> readAttrs = session.GetAttributeValue(key,new List<CKA>() {CKA.CKA_VALUE,CKA.CKA_CHECK_VALUE });
byte[] Key = readAttrs[0].GetValueAsByteArray();
byte[] KeyCheck1 = readAttrs[1].GetValueAsByteArray();
richTextBox1.Text += "\n Key :" + BitConverter.ToString(Key);
richTextBox1.Text += "\n Kcv :" + BitConverter.ToString(KeyCheck1);
}
通过使用此代码,我可以检索生成的密钥,但不能检索 KCV。如何从 HSM 检索 KCV。 (注意:生成的密钥不敏感)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)