我有一个存储在证书库中的X509Certificate2证书,我想将其导出为一个包含私钥的字节数组。这个证书字节数组必须是这样的,以便当我稍后从字节数组中导入证书时,私钥也会随之导入。
我尝试了很多方法,但没有成功导出带私钥的证书。
X509Store store = new X509Store(StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509Certificate2 cert = store.Certificates[1];
byte[] certBytes = cert.GetRawCertData(); // Obviously does not work!
能否成功将带有私钥的证书导出为字节数组?
非常感谢您的帮助。
System.Security.Cryptography.CryptographicException: 'Key not valid for use in specified state.'
异常。 - Eivind Gussiås Løkseth