简体   繁体   English

我们如何在 windows 存储 + C# 中存储和检索包含私钥的证书

[英]How can we store and retrieve a certificate containing private key in a windows store + C#

In my Windows application I will get a certificate containing private key.在我的 Windows 应用程序中,我将获得一个包含私钥的证书。 The public key is with me.公钥在我身边。 I want to securely store this certificate in Windows secure folder and could be able to access this whenever required.我想将此证书安全地存储在 Windows 安全文件夹中,并且可以在需要时访问它。 Please help me to do this.请帮助我做到这一点。 Any sample program.任何示例程序。

I got a solution for how can we store certificate with private key.我得到了一个关于如何使用私钥存储证书的解决方案。

byte[] byteKey = DecodePrivateKey(Convert.FromBase64String(cryptoCertificateKey));
RSAParameters rsaParam = DecodeRSAPrivateKeyToRSAParam(byteKey);
                    var cspParams = new CspParameters
                    {
                        ProviderType = 1,
                        Flags = CspProviderFlags.UseUserProtectedKey | CspProviderFlags.NoPrompt};
 using (X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine))
{
store.Open(OpenFlags.ReadWrite); 
using (RSACryptoServiceProvider rsaProvider = new RSACryptoServiceProvider(cspParams))
                    {
                        rsaProvider.ImportParameters(rsaParam);
                        rsaProvider.PersistKeyInCsp = true;
X509Certificate2 x509Certificate = new X509Certificate2(cryptoCertificate, "123",
                            X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable |
                            X509KeyStorageFlags.PersistKeySet);
store.Add(x509Certificate);
}}

But I didn't get a solution that how to secure the privatekey with password但我没有得到如何用密码保护私钥的解决方案

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

相关问题 无法导入具有私钥的证书pfx从Windows Server 2012上的.net c#3.5存储 - Cannot import certificate pfx with private key to store from .net c# 3.5 on windows server 2012 如何存储/检索 RSA 公钥/私钥 - How to store/retrieve RSA public/private key 如何在没有私钥的情况下在证书存储中安装证书? - how to install the certificate in certificate store without private key? 证书存储区中证书的私钥不可读 - Private key of certificate in certificate-store not readable 如何使用C#在Windows上存储和检索凭据 - How to store and retrieve credentials on Windows using C# 如何使用C#检索Windows Store应用程序中的所有联系人 - How to retrieve all contacts in Windows Store app using c# 如何访问C#中的“证书注册请求”存储? - How can I access the “certificate enrollment requests” store in C#? 使用C#,如何以编程方式确定Windows证书存储中的证书是否已被禁用 - Using C#, how to programmatically determine if a certificate in a Windows certificate store has been disabled 如何使用 .Net (C#) 在 Windows 中安全地存储 AES 密钥? - How can I securly store an AES key in Windows with .Net (C#)? 将BouncyCastle X509证书+私钥(RSA)导入Windows证书存储 - Import BouncyCastle X509Certificate + Private Key (RSA) into Windows Certificate Store
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM