• 大小: 1.42MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-10-25
  • 语言: C#
  • 标签: RSA  pkcs8  xml  公私钥  

资源简介

RSA公私钥pkcs8格式, 不能被C#程序所用,需要转转换为C#用的xml格式。这是转换用的c#源程序。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
using System.Security.Cryptography;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender EventArgs e)
        {
            string pkey = this.pkcs8PublicKey.Text.Trim();
            int i1 = 0 i2 = 0;
            i1 = pkey.IndexOf(“--“);
            while (i1 >= 0)
            {
                i2 = pkey.IndexOf(“\n“ i1);
                if (i2 == -1) i2 = pkey.Length - 1;
                if (i1 < i2)
                {
                    pkey = pkey.Substring(0 i1) + pkey.Substring(i2 + 1);
                }
                i1 = pkey.IndexOf(“--“);
            }
            pkey = pkey.Replace(“\r“““).Replace(“\n“““);
            this.xmlPublicKey.Text = RSAConverter.RSAPublicKeyJava2DotNet(pkey);
        }

        private void button2_Click(object sender EventArgs e)
        {
            string pkey = this.pkcs8PrivateKey.Text.Trim();
            int i1 = 0 i2 = 0;
            i1 = pkey.IndexOf(“--“);
            while (i1 >= 0)
            {
                i2 = pkey.IndexOf(“\n“ i1);
                if (i2 == -1) i2 = pkey.Length - 1;
                if (i1 < i2)
                {
                    pkey = pkey.Substring(0 i1) + pkey.Substring(i2 + 1);
                }
                i1 = pkey.IndexOf(“--“);
            }
            pkey = pkey.Replace(“\r“ ““).Replace(“\n“ ““);
            this.xmlPrivateKey.Text = RSAConverter.RSAPrivateKeyJava2DotNet(pkey);
        }
    }
    class base64
    {
        /// 
        /// base64编码
        /// 

        /// 
        /// 
        public static string encode(byte[] bytes)
        {
            return Convert.Tobase64String(bytes);
        }
        /// 
        /// base64解码
        /// 

        /// 
        /// 
        public static byte[] decode(string str)
        {
            return Convert.Frombase64String(str);
        }
        /// 
        /// 中文转码
        /// 

        /// 
        /// 
        public static string GetChinese(byte[] buffer)
        {
            byte[] buffer2 = Encoding.Convert(Encoding.UTF8 Encoding.Default buffer 0 buffer.Length);
            string strBuffer = Encoding.Default.GetString(buffer2 0 buffer2.Length);
            return strBuffer;
        }
    }
    class RSAConverter
    {

        /// 

        /// RSA私钥格式转

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-10-18 11:37  WindowsFormsApplication2\
     文件     2236416  2017-08-08 13:20  WindowsFormsApplication2\BouncyCastle.Crypto.dll
     文件        7961  2017-10-18 11:27  WindowsFormsApplication2\Form1.Designer.cs
     文件        4873  2017-10-18 11:37  WindowsFormsApplication2\Form1.cs
     文件        5817  2017-10-18 11:27  WindowsFormsApplication2\Form1.resx
     文件         505  2017-10-18 09:42  WindowsFormsApplication2\Program.cs
     目录           0  2017-10-18 09:42  WindowsFormsApplication2\Properties\
     文件        1356  2017-10-18 09:42  WindowsFormsApplication2\Properties\AssemblyInfo.cs
     文件        2861  2017-10-18 09:42  WindowsFormsApplication2\Properties\Resources.Designer.cs
     文件        5612  2017-10-18 09:42  WindowsFormsApplication2\Properties\Resources.resx
     文件        1111  2017-10-18 09:42  WindowsFormsApplication2\Properties\Settings.Designer.cs
     文件         249  2017-10-18 09:42  WindowsFormsApplication2\Properties\Settings.settings
     文件        3881  2017-10-18 11:17  WindowsFormsApplication2\WindowsFormsApplication2.csproj
     目录           0  2017-10-18 09:42  WindowsFormsApplication2\bin\
     目录           0  2017-10-18 11:37  WindowsFormsApplication2\bin\Debug\
     文件     2236416  2017-08-08 13:20  WindowsFormsApplication2\bin\Debug\BouncyCastle.Crypto.dll
     文件       13312  2017-10-18 11:37  WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.exe
     文件       26112  2017-10-18 11:37  WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.pdb
     文件       22688  2017-10-18 11:37  WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.vshost.exe
     文件         490  2013-06-18 20:28  WindowsFormsApplication2\bin\Debug\WindowsFormsApplication2.vshost.exe.manifest
     目录           0  2017-10-18 09:42  WindowsFormsApplication2\obj\
     目录           0  2017-10-18 11:37  WindowsFormsApplication2\obj\Debug\
     文件         864  2017-10-18 09:42  WindowsFormsApplication2\obj\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        7207  2017-10-18 11:06  WindowsFormsApplication2\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2017-10-18 11:38  WindowsFormsApplication2\obj\Debug\TempPE\
     文件         180  2017-10-18 11:37  WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.Form1.resources
     文件         180  2017-10-18 11:37  WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.Properties.Resources.resources
     文件        1268  2017-10-18 11:37  WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.csproj.FileListAbsolute.txt
     文件        1012  2017-10-18 11:37  WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.csproj.GenerateResource.Cache
     文件       13312  2017-10-18 11:37  WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.exe
     文件       26112  2017-10-18 11:37  WindowsFormsApplication2\obj\Debug\WindowsFormsApplication2.pdb
............此处省略1个文件信息

评论

共有 条评论