我正尝试在符合PIV的智能卡上执行主动卡身份验证。有关更多详细信息,请参见this document的附录A.2。如何在.Net中使用PKCS#1 v1.5编码数据
我有相关的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?
对不起,你可以帮我。你说你有一个2048位的rsa密钥,所以数组需要长度为0x100。如果我有1024位密钥,它的大小是多少? – GregaMohorko 2017-02-04 04:18:30
我不确定,但可能是一半? 0x100是256,所以请尝试128或0x80。 – Ben 2017-02-05 15:31:04