asp.net - X509 Store throws error when published on server, but not when running on localhost ASP.NET CORE 5
问题描述
Im trying to add a certificate (p12 file) when sending an http request to swish api. It´s working good on local host but when publishing it live it throws me this error :
Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: Access is denied. at Internal.Cryptography.Pal.StorePal.FromSystemStore(String storeName, StoreLocation storeLocation, OpenFlags openFlags) at System.Security.Cryptography.X509Certificates.X509Store.Open(OpenFlags flags) at SwishWithClient.ClientFolder.Client.PrepareHttpClientAndHandler(HttpClientHandler& handler, HttpClient& client) in C:\Users\Jakob\source\repos\SwishWithClient\SwishWithClient\ClientFolder\Client.cs:line 95 at SwishWithClient.ClientFolder.Client.MakePaymentRequest(String phonenumber, Int32 amount, String message) in C:\Users\Jakob\source\repos\SwishWithClient\SwishWithClient\ClientFolder\Client.cs:line 210
This is the code im running to handle the cert :
using (X509Store store = new X509Store(StoreName.CertificateAuthority, StoreLocation.CurrentUser))
{
store.Open(OpenFlags.ReadWrite);
var certs = new X509Certificate2Collection();
certs.Import(_certificate.Path, _certificate.Password, X509KeyStorageFlags.DefaultKeySet);
foreach (X509Certificate2 cert in certs)
{
if (cert.HasPrivateKey)
{
handler.ClientCertificates.Add(cert);
}
else
{
store.Add(cert);
}
}
}
Is this something to do with file rights on the server that not grants acces to the p12 file ? I have very little understanding of the code itself, copied it from another repository thats also using swish api.
解决方案
推荐阅读
- python - Python - 将 title() 函数应用于列中的值
- python - iwconfig 对使用 crontab @reboot 启动的进程不可用?
- c# - 从包括空格在内的单行中读取字符,而不是从新行中读取字符
- anaconda - 安装包后,Conda 需要 20 多分钟才能解决环境问题
- spring - 验证 Webflux ReactiveMongo
- c# - CSV文件的强类型解析
- react-native - 未定义不是对象(评估'_this2.props.navigation.navigate') - React Native
- udp - 对于小于默认值 1472 的有效负载大小,gnuradio UDP 源块的正确 MTU 设置是什么?
- git - 如何将作者姓名添加到自定义 git 别名?
- c# - C# 类 System.Data.SqlClient 无法加载文件或程序集