我正在处理与有关当局提供的证书密钥(.pfx)文件的支付网关集成,而我正在处理localhost everything,因为我在WindowsServer2019中发布了I expected.But,我们在令牌生成过程中遇到了一些问题。
这是我们使用的令牌生成代码。
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时得到的响应。

这是api在windows server 2019中发布后的响应。

发布于 2020-02-10 14:22:41
问题就在这里:X509Store store = new X509Store(StoreLocation.CurrentUser);
这是在您的PC上工作的,因为您的证书存储在CurrentUser存储下,但是当您将应用程序部署到Windows时,运行应用程序的用户在其证书存储区中没有特定的证书。
将证书安装到LocalMachine证书存储区,并从那里获得证书:
X509Store store = new X509Store(StoreLocation.LocalMachine);或安装证书以更正CurrentUser存储(不推荐,用户可能是NetworkUser,或系统,.)
https://stackoverflow.com/questions/60151499
复制相似问题