[英]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.