我试图获取从Windows生成的公钥,并使用CryptoPP库验证签名。其中一个问题是,根据Windows,开发人员无法访问私钥,因此我需要使用Windows (RequestSignAsync())和公钥给我的签名。这个是可能的吗?
我已经基于这个WinRT示例创建了Windows接口的C#版本:https://github.com/Microsoft/Windows-universal-samples/tree/main/Samples/MicrosoftPassport
我有我不想让我们看到示例中提供的服务器代码的原因,所以我尝试用Crypto++验证签名。
然后将签名和公钥发送到此CryptoPP设置:
CryptoPP::RSA::PublicKey keyPublic;
keyPublic.Load(CryptoPP::StringSource(pubkey, true, new CryptoPP::Base64Decoder()).Ref() );
CryptoPP::RSASS<CryptoPP::PKCS1v15, CryptoPP::SHA256>::Verifier verifier(keyPublic);
bool bSignatureVerified = false;
std::string sigdata;
CryptoPP::StringSource ss(sig,true,
new CryptoPP::Base64Decoder(
new CryptoPP::StringSink(sigdata)
)); // Base64Decoder
CryptoPP::StringSource ss2(sigdata, true,
new CryptoPP::SignatureVerificationFilter(
verifier,
new CryptoPP::ArraySink((CryptoPP::byte*)&bSignatureVerified,
sizeof(bSignatureVerified)
)
)
);
if(!bSignatureVerified)
{
return -2; //signed message not valid
}
else
{
return 0;
}公钥和签名是从Windows界面发送的。由于某种原因,我在这里得到了一个失败的验证。
下面是Windows文档:https://learn.microsoft.com/en-us/windows/uwp/security/microsoft-passport
似乎与我的Crypto++逻辑(PKCS1v1.5,SHA256,ASN.1编码)相匹配,但我肯定遗漏了什么。
发布于 2022-06-08 20:41:53
看起来我不明白我需要传递签名和消息。
这似乎是可行的:
CryptoPP::StringSource ss(sig,true,
new CryptoPP::Base64Decoder(
new CryptoPP::StringSink(sigdata)
)); // Base64Decoder
CryptoPP::StringSource ssmsg(msg,true,
new CryptoPP::Base64Decoder(
new CryptoPP::StringSink(msgdata)
)); // Base64Decoder
CryptoPP::StringSource ss2(sigdata+msgdata, true,
new CryptoPP::SignatureVerificationFilter(
verifier,
new CryptoPP::ArraySink((CryptoPP::byte*)&bSignatureVerified,
sizeof(bSignatureVerified)
)
)
);https://stackoverflow.com/questions/72551295
复制相似问题