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);