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



