简体   繁体   English

C#解密与X.509证书没有私钥

[英]C# Decryption with X.509 certificate without private key

Client encrypts the message using the X.509 certificate and sends the encrypted message to my web server. 客户端使用X.509证书对消息进行加密,并将加密的消息发送到我的Web服务器。 The client has provided a X.509 certificate without a private key (exported as DER encoded binary X.509 (.cer)). 客户端提供了没有私钥的X.509证书(导出为DER编码二进制X.509(.cer))。 Now my task is to decrypt the message using the X.509 certificate that I have. 现在我的任务是使用我拥有的X.509证书解密消息。

Whenever I try to decrypt the message I get “The private key does not exist” exception which is expected as the certificate does not contain the private key. 每当我尝试解密消息时,我得到“私钥不存在”异常,这是预期的,因为证书不包含私钥。 Is it feasible to decrypt the message using the x.509 certificate without the private key? 在没有私钥的情况下使用x.509证书解密消息是否可行?

Secondly, if client provides the password separately for the certificate can I create an instance of X509Certificate2 and use it to decrypt the message like : 其次,如果客户端为证书单独提供密码,我可以创建X509Certificate2的实例并使用它来解密消息,如:

X509Certificate2 c = new X509Certificate2("filename", "password");

You will need the private key to decrypt the message. 您将需要私钥来解密消息。 For example, you can ask your client to provide you a .pfx file which contains the private key, however, this is a little backwards, as usually, with asymmetric encryption, the sender (your client) should be encrypting the message with the receiver's (your) public key, which you decrypt with the receiver's (your) private key. 例如,您可以要求您的客户端为您提供包含私钥的.pfx文件,但是,这有点向后,通常使用非对称加密,发件人(您的客户端)应该使用接收者加密消息(您的)公钥,您使用接收方(您的)私钥解密。 That way the private key is not shared out to multiple parties, which reduces the chance that it gets compromised. 这样,私钥不会被多方共享,这降低了它被泄露的可能性。 The whole idea of a private key is that it's private - only the owner of the key gets to use it. 私钥的整个想法是它是私有的 - 只有密钥的所有者才能使用它。

Edit: As for the second question, a password is not the private key. 编辑:至于第二个问题,密码不是私钥。 You can generate a private key that is protected by a password. 您可以生成受密码保护的私钥。 That means in order to use the private key to do the decryption, you also have to know the password that protects that private key. 这意味着,为了使用私钥进行解密,您还必须知道保护该私钥的密码。

Edit 2: I'm not sure if this helps, but I struggled to understand how to practically apply a lot of these concepts a while back, so I wrote a series of blog posts that might help you. 编辑2:我不确定这是否有帮助,但我很难理解如何在一段时间内实际应用这些概念,所以我写了一系列可能对你有帮助的博客文章 I don't claim to be a security expert, but what I've written might get you started. 我并不自称是安全专家,但我写的内容可能会让你开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 X.509 Certificate.pfx 文件私钥在 C# 中的 OpenPGP 解密 - OpenPGP decryption in C# with X.509 Certificate .pfx file private key 导出X.509证书没有私钥 - Exporting X.509 certificate WITHOUT private key 如何在 C#/Xamarin 中使用带有来自 android 钥匙串的私钥的 X.509 证书? - How can I use an X.509 certificate with private key from the android keychain in C#/Xamarin? 为什么会出错X.509证书中不存在私钥 - Why getting error The private key is not present in the X.509 certificate 将私钥添加到 X509Certificate2 - C# - Adding a private key to X509Certificate2 - C# 在 C# 中生成 X.509 证书密钥对和签名请求 (CSR) - Generate X.509 certificate key pair and signing request (CSR) in C# 如何在C#中解析(转换为RSAParameters)X.509私钥? - How to parse(Convert to RSAParameters) X.509 private key in C#? 在C#中,使用x.509证书签署xml并检查签名 - In C#, sign an xml with a x.509 certificate and check the signature 证书管理器中提供的代码 bu 中的 X.509 证书中不存在私钥 - The private key is not present in the X.509 certificate from code bu available in certificate manager 如何设置对.NET X.509 证书私钥文件的读取权限 - How to set read permission on the private key file of X.509 certificate from .NET
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM