C# Pkcs11Interop.PDF库中私钥的标识
我正在尝试使用扩展设置一个示例应用程序。不幸的是,我得到一个C# Pkcs11Interop.PDF库中私钥的标识,c#,pdf,itext,pkcs#11,pkcs11interop,C#,Pdf,Itext,Pkcs#11,Pkcs11interop,我正在尝试使用扩展设置一个示例应用程序。不幸的是,我得到一个系统。ArgumentNullException设置ckaId。这里有什么用?我在这里尝试了不同的数字,它们都给了我一个系统。ArgumentOutOfRangeException 安装程序正在使用VirtualCryptoki-64-1.0.6.7.exe应用程序模拟智能卡 令人不安的是: pkcs11RsaSignature = new Pkcs11RsaSignature(libraryPath, tokenSerial, tok
系统。ArgumentNullException
设置ckaId。这里有什么用?我在这里尝试了不同的数字,它们都给了我一个系统。ArgumentOutOfRangeException
安装程序正在使用VirtualCryptoki-64-1.0.6.7.exe应用程序模拟智能卡
令人不安的是:
pkcs11RsaSignature = new Pkcs11RsaSignature(libraryPath, tokenSerial, tokenLabel, pin, ckaLabel, ckaId, hashAlgorithm);
我使用的哈希算法是:
HashAlgorithm hashAlgorithm = HashAlgorithm.SHA256;
使用pkcs11工具后更新:
虚拟卡的内容是:
C:\Program Files\OpenSC Project\OpenSC\tools>pkcs11-tool.exe --module "C:\windows\System32\vcki.dll" --list-slots --list-objects --login --pin 1234
Available slots:
Slot 0 (0xd47db04d): Virtual Smart Card Reader
token label: Virtual SC-A0101010101
token manuf: Cryptware
token model: VirtualSmartCard
token flags: rng, login required, PIN initialized, token initialized, other flags=0x200
serial num :
Using slot 0 with a present token (0xd47db04d)
Certificate Object, type = X.509 cert
label: ibisit
ID: 4a656e73204b6175666d616e6e
Public Key Object; RSA 1024 bits
label: ibisit
ID: 4a656e73204b6175666d616e6e
Usage: encrypt, verify
Private Key Object; RSA
label: ibisit
ID: 4a656e73204b6175666d616e6e
Usage: decrypt, sign
warning: PKCS11 function C_GetAttributeValue(ALWAYS_AUTHENTICATE) failed: rv = CKR_ATTRIBUTE_TYPE_INVALID (0x12)
Public Key Object; RSA 1024 bits
label: ibisit
ID: 4a656e73204b6175666d616e6e
Usage: encrypt, verify
Private Key Object; RSA
label: ibisit
ID: 4a656e73204b6175666d616e6e
Usage: decrypt, sign
warning: PKCS11 function C_GetAttributeValue(ALWAYS_AUTHENTICATE) failed: rv = CKR_ATTRIBUTE_TYPE_INVALID (0x12)
我使用的参数是:
string libraryPath = @"C:\Windows\System32\vcki.dll";
string tokenSerial = null;
string tokenLabel = @"Virtual SC-A0101010101";
string pin = @"1234";
string ckaLabel = @"ibisit";
string ckaId = "4a656e73204b6175666d616e6e";
HashAlgorithm hashAlgorithm = HashAlgorithm.SHA256;
不幸的是,我得到了一个Net.Pkcs11Interop.PDF.ObjectNotFoundException
设置ckaId。更改pin会给我一个不同的异常,因此我肯定会在这里访问正确的设备
切换到SoftHSM后更新:
jariq说有太多具有相同id的对象出现了问题。不幸的是,虚拟密钥管理器不允许我删除任何对象,所以我切换到SoftHSM(我刚开始使用它)。我正在获取“未找到标签为“ibis it密钥”且id为“A1B2”的证书”。我想这里的问题是,这个虚拟卡只持有RSA密钥对,而不是证书
pkcs11工具的输出为:
C:\Program Files (x86)\OpenSC Project\OpenSC\tools>pkcs11-tool.exe --module "C:\SoftHSM\lib\libsofthsm.dll" --list-slots --list-objects --login --pin smart
Available slots:
Slot 0 (0x0): SoftHSM
token label: SoftHSM
token manuf: SoftHSM
token model: SoftHSM
token flags: rng, login required, PIN initialized, token initialized, other flags=0x40
serial num : 1
Using slot 0 with a present token (0x0)
Public Key Object; RSA 2048 bits
label: ibis-it key
ID: a1b2
Usage: verify
Private Key Object; RSA
label: ibis-it key
ID: a1b2
Usage: sign
问题是SoftHSM只导入PKCS#8(RSA)密钥对,因此这里永远不会有证书。我想您已经将其用于RSA密钥对,而不是证书。传递给Net.Pkcs11Interop.PDF.Pkcs11RsaSignature类构造函数的参数标识以下内容:
- 应该使用哪个PKCS#11库(libraryPath)
- 哪个令牌/智能卡存储私钥(令牌串行和/或令牌标签)
- 应使用哪个私钥进行签名(ckaLabel和/或ckaId)
- 签名创建期间应使用哪种哈希算法(哈希算法)
C:\SoftHSM\bin>softhsm.exe --import doe.key --slot 0 --label "John Doe" --pin 11111111 --id "ec5e50a889b888d600c6e13cb0fdf0c1"
The key pair has been imported to the token in slot 0.
C:\SoftHSM\bin>"c:\Program Files (x86)\OpenSC Project\OpenSC\tools\pkcs11-tool.exe" --module libsofthsm.dll --login --pin 11111111 --write-object doe.der --type cert --label "John Doe" --id "ec5e50a889b888d600c6e13cb0fdf0c1"
Using slot 0 with a present token (0x0)
Created certificate:
Certificate Object, type = X.509 cert
label: John Doe
ID: ec5e50a889b888d600c6e13cb0fdf0c1
请确保导入的证书的ID与私钥的ID相同。谢谢您的详细回答。您提供链接的工具非常方便。不幸的是,它还没有解决我的问题。我去掉了“ArgumentNullException”,但现在得到了一个“Net.Pkcs11Interop.PDF.ObjectNotFoundException”异常,还有一个异常:带有标签“ibisit”和id“4A656E73204B6175666D616E6E”的私钥。我不确定在stackoverflow上如何正确处理这个主题。我将尝试更改该问题。@ejones在发布答案后完全更改该问题被认为不是一种好的做法。我已经用ObjectNotFoundException的信息编辑了您的问题和答案。非常感谢您的支持!现在这完全有道理了。不幸的是,Cryptoware Cryptoki Explorer不允许我通过其GUI或pkcs11-tool.exe删除任何内容。我将再次切换到SoftHSM工具(我从这里开始),并检查我是否在这里遇到了问题/我终于把它安装好并运行起来了。PDF扩展非常简单!谢谢!
C:\SoftHSM\bin>"c:\Program Files (x86)\OpenSC Project\OpenSC\tools\pkcs11-tool.exe" --module libsofthsm.dll --login --pin 11111111 --write-object doe.der --type cert --label "John Doe" --id "ec5e50a889b888d600c6e13cb0fdf0c1"
Using slot 0 with a present token (0x0)
Created certificate:
Certificate Object, type = X.509 cert
label: John Doe
ID: ec5e50a889b888d600c6e13cb0fdf0c1