• 大小: 620KB
    文件类型: .rar
    金币: 2
    下载: 5 次
    发布日期: 2021-05-22
  • 语言: Java
  • 标签: C#  RSA  md5  java  

资源简介

C# RSA加密、解密、加签、验签、支持JAVA格式公钥私钥、PEM格式公钥私钥、.NET格式公钥私钥支持证书

资源截图

代码片段和文件信息

using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
using System.ComponentModel;

namespace WNSLP.Toolkits.Extensions
{
    public static class RSAExtensions
    {
        /// 
        ///  把java的私钥转换成.net的xml格式
        /// 

        /// 
        /// 
        /// 
        public static string ConvertToxmlPrivateKey(this RSA rsa string privateJavaKey)
        {
            RsaPrivateCrtKeyParameters privateKeyParam = (RsaPrivateCrtKeyParameters)PrivateKeyFactory.CreateKey(Convert.Frombase64String(privateJavaKey));
            string xmlPrivateKey = string.Format(“{0}{1}

{2}

{3}{4}{5}{6}{7}

                         Convert.Tobase64String(privateKeyParam.Modulus.ToByteArrayUnsigned())
                         Convert.Tobase64String(privateKeyParam.PublicExponent.ToByteArrayUnsigned())
                         Convert.Tobase64String(privateKeyParam.P.ToByteArrayUnsigned())
                         Convert.Tobase64String(privateKeyParam.Q.ToByteArrayUnsigned())
                         Convert.Tobase64String(privateKeyParam.DP.ToByteArrayUnsigned())
                         Convert.Tobase64String(privateKeyParam.DQ.ToByteArrayUnsigned())
                         Convert.Tobase64String(privateKeyParam.QInv.ToByteArrayUnsigned())
                         Convert.Tobase64String(privateKeyParam.Exponent.ToByteArrayUnsigned()));
            return xmlPrivateKey;
        }
        /// 
        /// RSA加载JAVA  PrivateKey
        /// 

        /// java提供的第三方私钥
        /// 
        public static void FromPrivateKeyJavaString(this RSA rsa string privateJavaKey)
        {
            string xmlPrivateKey = rsa.ConvertToxmlPrivateKey(privateJavaKey);
            rsa.FromxmlString(xmlPrivateKey);
        }

        /// 
        /// 把java的公钥转换成.net的xml格式
        /// 

        /// java提供的第三方公钥
        /// 
        public static string ConvertToxmlPublicJavaKey(this RSA rsa string publicJavaKey)
        {
            RsaKeyParameters publicKeyParam = (RsaKeyParameters)PublicKeyFactory.CreateKey(Convert.Frombase64String(publicJavaKey));
            string xmlpublicKey = string.Format(“{0}{1}
              Convert.Tobase64String(publicKeyParam.Modulus.ToByteArrayUnsigned())
              Convert.Tobase64String(publicKeyParam.Exponent.ToByteArrayUnsigned()));
    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       7120  2017-01-16 14:14  RSAHelperTest.cs

     文件    2236416  2017-01-11 20:43  BouncyCastle.Crypto.dll

     文件      17798  2017-01-14 17:58  RSAExtensions.cs

----------- ---------  ---------- -----  ----

              2261334                    3


评论

共有 条评论