要将.NET中的RSA公钥导入OpenSSL,请按照以下步骤操作:
using System;
using System.IO;
using System.Security.Cryptography;
public static void ExportPublicKeyToPem(RSA rsa, string fileName)
{
byte[] publicKeyBytes = rsa.ExportRSAPublicKey();
using (var sw = new StreamWriter(fileName))
{
sw.WriteLine("-----BEGIN PUBLIC KEY-----");
sw.WriteLine(Convert.ToBase64String(publicKeyBytes, Base64FormattingOptions.InsertLineBreaks));
sw.WriteLine("-----END PUBLIC KEY-----");
}
}
openssl rsa -in public_key.pem -outform DER -out public_key.der
openssl rsa -inform DER -in public_key.der -outform PEM -out public_key_der_to_pem.pem
现在,您已经成功将.NET中的RSA公钥导入OpenSSL。
推荐的腾讯云相关产品:
领取专属 10元无门槛券
手把手带您无忧上云