我正在尝试使用Pkcs11Interop.PDF扩展名设置示例应用程序。不幸的是,我正在System.ArgumentNullException
设置ckaId。什么在这里工作?我在这里尝试了不同的数字,它们都给了我一个System.ArgumentOutOfRangeException
.
该设置使用 VirtualCryptoki-64-1.0.6.7.exe 应用程序来模拟智能卡。
令人不安的电话是:
pkcs11RsaSignature = new Pkcs11RsaSignature(libraryPath, tokenSerial, tokenLabel, pin, ckaLabel, ckaId, hashAlgorithm);
我使用的哈希算法是:
HashAlgorithm hashAlgorithm = HashAlgorithm.SHA256;
使用 pkcs11-tool 后更新:
虚拟卡的内容是:
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 的对象存在问题。不幸的是,Virtual Key Explorer 不允许我删除任何对象,所以我切换到 SoftHSM(我一开始就使用它)。我收到“未找到带有标签“ibis-it key”和 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 密钥对一起使用,但没有与证书一起使用。