问题描述
美好的一天!我正在尝试基于通过邮寄请求来自客户端的十六进制字符串创建公共密钥 ObjectHandle
.
Good day!I'm trying to create public key ObjectHandle
based on hex string that comes from client via post request.
我正在按照文档进行操作,但是它返回了我 CKR_ATTRIBUTE_TYPE_INVALID
实例.
I'm doing it according to the documentation, but it returns me CKR_ATTRIBUTE_TYPE_INVALID
exeption.
完整示例消息: Net.Pkcs11Interop.Common.Pkcs11Exception:'方法C_CreateObject返回了CKR_ATTRIBUTE_VALUE_INVALID'
内部异常为空
您能帮我弄清楚我在做什么错吗?
Can you please help me to figure out what i'm doing wrong?
这是我的代码:
using (Pkcs11 pkcs11 = new Pkcs11(Settings.RutokenEcpDllDefaultPath, AppType.MultiThreaded))
{
Slot slot = GetSlot(pkcs11);
// This public key comes from client
// But i put it here to show value. Maybe value is a reason. I'm not sure,
// but i hope you will help me
var hexString = "1c:ec:2d:4a:b3:51:51:07:f7:c4:f6:d9:09:a3:06:73:c2:06:42:7f:b2:11:fd:be:ad:12:5c:22:b9:df:cb:e5:08:7c:7c:48:a6:af:92:67:d3:56:63:29:0c:9e:1a:4a:0e:d1:08:d8:7a:28:61:bd:da:ed:be:aa:49:84:f2:64";
hexString = hexString.Replace(":", string.Empty);
var publicKeyValue = ConvertUtils.HexStringToBytes(hexString);
using (Session session = slot.OpenSession(SessionType.ReadWrite))
{
session.Login(CKU.CKU_USER, Settings.TokenPin);
List<ObjectAttribute> objectAttributes = new List<ObjectAttribute>();
objectAttributes.Add(new ObjectAttribute(CKA.CKA_CLASS, CKO.CKO_PUBLIC_KEY));
objectAttributes.Add(new ObjectAttribute(CKA.CKA_KEY_TYPE, CKK.CKK_GOSTR3410));
objectAttributes.Add(new ObjectAttribute(CKA.CKA_LABEL, "Verification Key"));
objectAttributes.Add(new ObjectAttribute(CKA.CKA_VERIFY, true));
objectAttributes.Add(new ObjectAttribute(CKA.CKA_VALUE, publicKeyValue));
objectAttributes.Add(new ObjectAttribute(CKA.CKA_TOKEN, true));
objectAttributes.Add(new ObjectAttribute(CKA.CKA_PRIVATE, false));
objectAttributes.Add(new ObjectAttribute(CKA.CKA_GOSTR3410_PARAMS, new byte[] { 0x06, 0x07, 0x2a, 0x85, 0x03, 0x02, 0x02, 0x23, 0x00 }));
// Create object
ObjectHandle objectHandle = session.CreateObject(objectAttributes);
}
}
推荐答案
GOST公钥无法导入到ruToken中-请参见文档框中的注释.
GOST Public Key can't be imported onto ruToken - see docs note in the box.
只需更改
objectAttributes.Add(new ObjectAttribute(CKA.CKA_TOKEN,** true **));
到
objectAttributes.Add(new ObjectAttribute(CKA.CKA_TOKEN,** false **));
仅作为 C_GenerateKeyPair
调用的结果,才能创建"作为令牌对象的公钥.
Public key as a token object can only be 'created' as a result of C_GenerateKeyPair
call.
这篇关于我正在尝试创建GOSTR3410公钥.CKR_ATTRIBUTE_TYPE_INVALID样本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!