using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.IO;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Crypto;
public sealed class CryptoHelper
{
/// <summary>
/// RSA密钥转Pem密钥
/// </summary>
/// <param name="RSAKey">RSA密钥</param>
/// <param name="isPrivateKey">是否是私钥</param>
/// <returns>Pem密钥</returns>
public static string RSAKeyToPem(string RSAKey, bool isPrivateKey)
{
string pemKey = string.Empty;
var rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(RSAKey);
RSAParameters rsaPara = new RSAParameters();
RsaKeyParameters key = null;
//RSA私钥
if (isPrivateKey)
{
rsaPara=rsa.ExportPa
C# 调用BouncyCastle将RSA密钥与pem格式进行互转
最新推荐文章于 2024-09-14 08:42:10 发布
本文介绍了如何在C#中利用BouncyCastle库,将RSA密钥进行PEM格式的转换。包括将RSA私钥转换为PEM格式,RSA公钥转换为PEM格式,以及将PEM格式还原为RSA私钥和公钥的详细步骤。
摘要由CSDN通过智能技术生成