3 回答

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超6個(gè)贊
關(guān)于輕松導(dǎo)入RSA私鑰,不使用BouncyCastle等第三方代碼,我認(rèn)為答案是“不,不是單獨(dú)使用私鑰的PEM”。
但是,正如Simone所提到的,您可以簡(jiǎn)單地將私鑰(* .key)的PEM和使用該密鑰(* .crt)的證書文件組合成* .pfx文件,然后可以輕松導(dǎo)入該文件。
要從命令行生成PFX文件:
openssl pkcs12 -in a.crt -inkey a.key -export -out a.pfx
然后正常使用.NET證書類,例如:
using System.Security.Cryptography.X509Certificates;
X509Certificate2 combinedCertificate = new X509Certificate2(@"C:\path\to\file.pfx");
現(xiàn)在,您可以按照MSDN中的示例通過RSACryptoServiceProvider進(jìn)行加密和解密:
我遺漏了解密,你需要使用PFX密碼和Exportable標(biāo)志導(dǎo)入。(參見:BouncyCastle RSAPrivateKey到.NET RSAPrivateKey)
X509KeyStorageFlags flags = X509KeyStorageFlags.Exportable;
X509Certificate2 cert = new X509Certificate2("my.pfx", "somepass", flags);
RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)cert.PrivateKey;
RSAParameters rsaParam = rsa.ExportParameters(true);
- 3 回答
- 0 關(guān)注
- 1388 瀏覽
添加回答
舉報(bào)