我正在与有关当局提供的证书密钥(.pfx)文件进行支付网关集成,虽然我在本地主机上工作,但一切都按我的预期完美运行。但是在我在 Windows Server 2019 中发布后,我们遇到了一些问题令牌生成过程。
这是我们使用的令牌生成代码
RSACng key = new System.Security.Cryptography.RSACng();
X509Certificate2 publicCert = new X509Certificate2(publicKeyLocation, "123", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet);
X509Certificate2 privateCert = null;
X509Store store = new X509Store(StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
foreach (X509Certificate2 cert in store.Certificates)
{
var val1 = publicCert.GetCertHashString();
if (cert.GetCertHashString() == publicCert.GetCertHashString())
privateCert = cert;
}
key = privateCert.GetRSAPrivateKey() as RSACng;
byte[] signature = key.SignHash(hashValue, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
key = (System.Security.Cryptography.RSACng)publicCert.GetRSAPublicKey();
if (!key.VerifyHash(hashValue, signature, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1))
throw new CryptographicException();
return signature;
这是我们从localhost调用 api 时得到的响应
这是我们在windows server 2019发布后api的响应