.NET使用OpenSSL生成的pem密钥文件【做电子商务的朋友可能需要】
using System;
using System.Text;
using System.Security.Cryptography;
using System.Web;
using System.IO;
namespace Thinhunan.Cnblogs.Com.RSAUtility
{
public class PemConverter
{
/// <summary>
/// 将pem格式公钥转换为RSAParameters
/// </summary>
/// <param name="pemFileConent">pem公钥内容</param>
/// <returns>转换得到的RSAParamenters</returns>
public static RSAParameters ConvertFromPemPublicKey(string pemFileConent)
{
if (string.IsNullOrEmpty(pemFileConent))
{
throw new ArgumentNullException("pemFileConent", "This arg cann't be empty.");
}
pemFileConent = pemFileConent.Replace("-----BEGIN PUBLIC KEY-----", "").Replace("-----END PUBLIC KEY-----", "").Replace("\n", "").Replace("\r", "");
byte[] keyData = Convert.FromBase64String(pemFileConent);
if (keyData.Length < 162)
{
throw new ArgumentException("pem file content is incorrect.");
}
byte[] pemModulus = new byte[128];
byte[] pemPublicExponent = new byte[3];
Array.Copy(keyData, 29, pemModulus, 0, 128);
Array.Copy(keyData, 159, pemPublicExponent, 0, 3);
RSAParameters para = new RSAParameters();
para.Modulus = pemModulus;
相关新闻>>
- 发表评论
-
- 最新评论 进入详细评论页>>
今日头条
更多>>您可能感兴趣的文章
- Spring.Net学习系列一: 统一异常处理
- 使用ASP.NET MVC3+EF+Jquery制作文字直播系统(一
- 用OpenXml在文档的尾部添加一个Rich Text Content Con
- Request.Cookies 和 Response.Cookies 的区别
- 向Excel文档中嵌入VBA控件和UserForm并显示
- ASP.net页面中请求远程Web站点
- ASP.NET之Gridview图解(1)
- ASP.NET FormsAuthentication跨站点登录时绝对地址返
- 步步为营 SharePoint 开发学习笔记系列&nb
- ASP.NET生成高质量缩略图通用函数(c#代码)



