在使用 X.509 证书的非对称加密中使用 public 密钥
Using public key in asymmetric encryption with X.509 certificates
前段时间我读到一篇关于使用 public 等非对称密钥和私钥安全发送数据的文章。我所了解的是 服务器 有 1 个密钥 (私钥) 用于加密数据和所有 客户端使用第二个密钥(public密钥)解密
现在我应该如何接收密钥以及我应该如何使用它?
如果我从服务器收到证书,它不会同时包含 public 和私钥吗?!
X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
var cert = GetCertificate(certStore);
var privatekey= cert.PrivateKey;
var publicKey= cert.PublicKey;
是否可以从证书中删除私钥?如何?以及我如何知道证书是否有私钥?
首先澄清一点:
在Public-key cryptography中,public密钥用于加密数据,私钥(由服务器)用于解密数据。
私钥的拥有者存储私钥,只共享一个public密钥。
来自服务器的任何证书都应该包含 only a public key。
(如果证书中包含私钥,那将是一个很大的安全问题。您可以解密来自任何其他用户的消息)
要检查证书是否有私钥,您可以使用 HasPrivateKey-Property
cert.HasPrivateKey;
要获得仅包含 public 密钥的证书,您可以使用:
byte[] bytes = cert.Export(X509ContentType.Cert);
var publicCert = new X509Certificate2(bytes);
If I receive a Certificate from the server, wouldn't it contain both public and private keys?!
不,不一定。
获取证书有两种不同的方式
- PKCS#7/PEM - 该文件通常只包含证书的 public 部分
- PKCS#12/PFX - 存储包含带私钥的证书
Is it possbile to remove the private key from the certificate?
通过将其导出为允许您仅存储证书的 public 部分的格式。
打开网络浏览器,导航到任何使用 SSL 的站点。
现在单击锁图标,然后单击证书信息。您在客户端(在浏览器中)拥有的是 没有 私钥的证书。您可以保存它甚至导入到系统证书存储区,但仍然没有私钥。
and how can I understand if the certificate has the private key?
如果您使用 C# 代码加载它,访问 HasPrivateKey
属性 将 true
仅适用于具有可用私钥的证书。
前段时间我读到一篇关于使用 public 等非对称密钥和私钥安全发送数据的文章。我所了解的是 服务器 有 1 个密钥 (私钥) 用于加密数据和所有 客户端使用第二个密钥(public密钥)解密
现在我应该如何接收密钥以及我应该如何使用它?
如果我从服务器收到证书,它不会同时包含 public 和私钥吗?!
X509Store certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
var cert = GetCertificate(certStore);
var privatekey= cert.PrivateKey;
var publicKey= cert.PublicKey;
是否可以从证书中删除私钥?如何?以及我如何知道证书是否有私钥?
首先澄清一点:
在Public-key cryptography中,public密钥用于加密数据,私钥(由服务器)用于解密数据。
私钥的拥有者存储私钥,只共享一个public密钥。 来自服务器的任何证书都应该包含 only a public key。 (如果证书中包含私钥,那将是一个很大的安全问题。您可以解密来自任何其他用户的消息)
要检查证书是否有私钥,您可以使用 HasPrivateKey-Property
cert.HasPrivateKey;
要获得仅包含 public 密钥的证书,您可以使用:
byte[] bytes = cert.Export(X509ContentType.Cert);
var publicCert = new X509Certificate2(bytes);
If I receive a Certificate from the server, wouldn't it contain both public and private keys?!
不,不一定。
获取证书有两种不同的方式
- PKCS#7/PEM - 该文件通常只包含证书的 public 部分
- PKCS#12/PFX - 存储包含带私钥的证书
Is it possbile to remove the private key from the certificate?
通过将其导出为允许您仅存储证书的 public 部分的格式。
打开网络浏览器,导航到任何使用 SSL 的站点。
现在单击锁图标,然后单击证书信息。您在客户端(在浏览器中)拥有的是 没有 私钥的证书。您可以保存它甚至导入到系统证书存储区,但仍然没有私钥。
and how can I understand if the certificate has the private key?
如果您使用 C# 代码加载它,访问 HasPrivateKey
属性 将 true
仅适用于具有可用私钥的证书。