如何将.crt文件转换为C#中的.pem文件
我有CRT文件,需要通过C#中的代码将其转换为PEM,该怎么办?
openssl中的命令:
openssl x509 -inform der -in file.crt -out file.pem
I have the crt file and I need to convert it to pem by code in C#, how can I do that?
command in openssl:
openssl x509 -inform der -in file.crt -out file.pem
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在.NET的现代版本上,您可以使用 pemencoding class:
.net 7:
.net 5:
但是,在“石头衰老” .NET框架您必须编写相当简单的转换自己(
$” ------开始{label} ------ \ n {convert.tobase64string(der,base64form64form64form64formattingoptions.includenewlines)) } \ n -----结束{label} ----- \ n“
是简短的表单)。从https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.x509certificates.certificateate.certificaterequest.c ReatesigningRequest?view = net-6.0#系统 - 安全性 - ryptography-x509certificates-certificateTificateRequest-CreateSigningRequestRequest :
On modern versions of .NET you can use the PemEncoding class:
.NET 7:
.NET 5:
But, in "stone-aged" .NET Framework you have to write the fairly easy transform yourself (
$"-----BEGIN {label}-----\n{Convert.ToBase64String(der, Base64FormattingOptions.IncludeNewLines)}\n-----END {label}-----\n"
being the short form).Borrowed/tweaked from the Remarks section of https://learn.microsoft.com/en-us/dotnet/api/system.security.cryptography.x509certificates.certificaterequest.createsigningrequest?view=net-6.0#system-security-cryptography-x509certificates-certificaterequest-createsigningrequest: