C# x509Certificate2无法创建

C# x509Certificate2 cannot be created
2021-02-23
  •  译文(汉语)
  •  原文(英语)

即时通讯通过我从Apple .p12文件制作的字节数组创建证书.

X509Certificate2 cert = new X509Certificate2(AppleCertBytes, ApplePassword);

仅当im在本地主机上时,此方法才能正常工作并创建cert,BUT.

当我构建WebService并将其发布到服务器时,它不起作用.

我将日志放置在任何可能的地方,并且我注意到运行此行时请求已消失.

服务器无响应,有时甚至无响应Err: connection_reset.当我调试过程时,我没有看到任何错误,并且我认为.dll文件可能是问题错误,我认为我用不同的日志对其进行了11次检查,而且似乎随时都在更新.

编辑 不会引发异常.

我在这里想念什么吗?可能是ApplicationPool,还是插件?

请注意.

我不要创建证书的任何插件,我想要可能的结果.谢谢.

速聊1:
所以要清楚一点:那行不会引发异常?
速聊2:
是的,忘了说.没有例外.
速聊3:
该证书中的CA是否在该服务器上的正确存储中?用于该应用程序域的身份是否具有访问证书存储区的权限?
速聊4:
请解释?我不是证书专家.
速聊5:
如果您在本地打开该证书,它是否显示证书链?(如果打开证书,则可以在"证书路径"选项卡属性对话框中找到).服务器上还必须存在那里的所有证书以及颁发者...
解决过程1

您需要使用构造函数的另一个重载将私钥存储在本地计算机存储中.

您的构造函数应显示为:

var cert = new X509Certificate2(
                        AppleCertBytes, 
                        ApplePassword,
                        X509KeyStorageFlags.MachineKeySet);
速聊1:
你救了我的命.谢谢!

im creating a certificate via a byte array I make from an Apple .p12 file.

X509Certificate2 cert = new X509Certificate2(AppleCertBytes, ApplePassword);

this works fine and creates the cert,BUT, only when im on localhost.

When i build and publish my WebService to the server it doesn't work.

I placed logs wherever I can, and i noticed that the request sort of gone when running this row.

I get no response for server and sometimes even get Err: connection_reset. When i debug the process i don't see any errors, and i thought maybe the .dll file was the issue bug I think i checked it for like 11 times with different logs and it seems updated at anytime.

EDIT No exception is thrown.

Is there anything I'm missing here? ApplicationPool maybe, plugin or such?

PLEASE NOTICE.

I DON'T want any plugins that create the certificate, i want a possible results. Thanks.

Talk1:
So just to be clear: that line doesn't throw an exception?
Talk2:
Yeah, forgot to say. no exception is caught.
Talk3:
Is the CA from that certificate in the correct store on that server? Does the identity used for that appdomain have persmission to access the certificate store?
Talk4:
please explain? i'm not an expert in certificates.
Talk5:
If you open that certificate locally does it show a cetificate chain? (you can find that on the certificate path tab properties dialog if you open a certificate). All certificates there as well as the issuer need to exist on the server as well...
Solutions1

You need to use another overload of the constructor to store the private keys in the local computer store.

Your constructor should read:

var cert = new X509Certificate2(
                        AppleCertBytes, 
                        ApplePassword,
                        X509KeyStorageFlags.MachineKeySet);
Talk1:
You saved my live. Thank you!
转载于:https://stackoverflow.com/questions/23732967/c-sharp-x509certificate2-cannot-be-created

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入