1、第一步先用openssl将pem的key转换为der的key //E:\01Doc\bin>openssl.exe rsa -in rsakeydec.pem -outform der -out pri.der
2、调用下面的程序直接读取der转换为c#所需要的xml Key,之后进行密文解密
3、openssl下载地址
http://download.csdn.net/download/jiayanhui2877/4089521
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Security.Cryptography;
using System.ComponentModel;
using System.Runtime.InteropServices;
/*refer: http://q.cnblogs.com/q/70822/
http://blog.chinaunix.net/uid-26729093-id-4449165.html*/
namespace ConsoleApplication1
{
class Program
{
private static int GetIntegerSize(BinaryReader binr)
{
byte bt = 0;
byte lowbyte = 0x00;
byte highbyte = 0x00;
int count = 0;
bt = binr.ReadByte();
if (bt != 0x02) //expect integer
return 0;
bt = binr.ReadByte();
if (bt == 0x81)
count = binr.ReadByte(); // data size in next byte
else
if (bt == 0x82)
{
highbyte = binr.ReadByte(); // data size in next 2 bytes
lowbyte = binr.ReadByte();
byte[] modint = { lowbyte, highbyte, 0x00, 0x00 };
count = BitConverter.ToInt32(modint, 0);

本文介绍了如何使用C#读取PEM格式的RSA密钥文件,并通过openssl工具将其转换为DER格式,进一步转换为C#可使用的XML Key,以便进行加密解密操作。详细步骤包括使用openssl的命令行工具进行转换,并提供了openssl的下载链接。
最低0.47元/天 解锁文章
124

被折叠的 条评论
为什么被折叠?



