【发布时间】:2011-01-14 15:43:01
【问题描述】:
我正在尝试在符合 PIV 的智能卡上执行主动卡身份验证。有关详细信息,请参阅this document 的附录 A.2。
我有来自相关 X.509 证书的公钥。我需要给卡发送一些随机数据,它会用它的私钥签名,然后我需要用公钥验证签名。
我所在的文档中的示例指出,他们发送的要签名的数据是“根据 PKCS #1 v1.5 签名填充方案编码的”。我如何像这样编码我的随机数据?我认为填充数据是 RSA 签名过程的一部分。
// Generate random data
byte[] randomData = new byte[128];
Random random = new Random();
random.NextBytes(randomData);
// Hash the random data
SHA1Managed sha1 = new SHA1Managed();
byte[] hash = sha1.ComputeHash(randomData);
// Send the hash to the Smart Card and get back signed data
byte[] signature = SendToSmartCardForSignature(hash);
// Verify the data and the signature match using the public key
RSACryptoServiceProvider rsa = smartCardCertificate.PublicKey;
bool verified = rsa.VerifyData(randomData, CryptoConfig.MapNameToOID("SHA1"), signature);
// verified is false...why?
【问题讨论】:
标签: .net compact-framework cryptography rsa smartcard