• 大小: 779KB
    文件类型: .zip
    金币: 2
    下载: 0 次
    发布日期: 2021-05-13
  • 语言: C#
  • 标签: RSA加解密  

资源简介

亲测可用,可参考:https://blog.csdn.net/qq_37835111/article/details/87358779

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;

/// 
/// 描述:RSA公钥加密私钥解密工具类
/// 功能:RSA公钥加密、私钥解密、私钥签名、公钥验签  
/// 作者:yoyohan
/// 创建时间:2019-02-12 09:49:41
/// 

public sealed class RSACrypt1
{
    ///   
    /// 私钥签名  
    /// 
  
    /// 待签名字符串  
    /// 私钥  
    /// 编码格式  
    /// 签名后字符串  
    public static string sign(string content string privateKey string input_charset)
    {
        byte[] Data = Encoding.GetEncoding(input_charset).GetBytes(content);
        RSACryptoServiceProvider rsa = DecodePemPrivateKey(privateKey);
        SHA1 sh = new SHA1CryptoServiceProvider();
        byte[] signData = rsa.SignData(Data sh);
        return Convert.Tobase64String(signData);
    }

    ///   
    /// 公钥验签  
    /// 
  
    /// 待验签字符串  
    /// 签名  
    /// 公钥  
    /// 编码格式  
    /// true(通过),false(不通过)  
    public static bool verify(string content string signedString string publicKey string input_charset)
    {
        bool result = false;
        byte[] Data = Encoding.GetEncoding(input_charset).GetBytes(content);
        byte[] data = Convert.Frombase64String(signedString);
        RSAParameters paraPub = ConvertFromPublicKey(publicKey);
        RSACryptoServiceProvider rsaPub = new RSACryptoServiceProvider();
        rsaPub.ImportParameters(paraPub);
        SHA1 sh = new SHA1CryptoServiceProvider();
        result = rsaPub.VerifyData(Data sh data);
        return result;
    }

    ///   
    /// 公钥加密  
    /// 
  
    /// 需要加密的字符串  
    /// 公钥  
    /// 编码格式  
    /// 明文  
    public static string encryptData(string resData string publicKey string input_charset)
    {
        byte[] DataToEncrypt = Encoding.ASCII.GetBytes(resData);
        string result = encrypt(DataToEncrypt publicKey input_charset);
        return result;
    }


    ///   
    /// 私钥解密  
    /// 
  
    /// 加密字符串  
    /// 私钥  
    /// 编码格式  
    /// 明文  
    public static string decryptData(string resData string privateKey string input_charset)
    {
        byte[] DataToDecrypt = Convert.Frombase64String(resData);
        string result = ““;
        for (int j = 0; j < DataToDecrypt.Length / 128; j++)
        {
            byte[] buf = new byte[128];
            for (int i = 0; i < 128; i++)
            {

                

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件     2371584  2018-04-08 23:30  RSATool\BouncyCastle.Crypto.dll
     文件       15569  2019-02-15 11:50  RSATool\RSACrypt1.cs
     文件        5394  2019-02-15 13:29  RSATool\RSACrypt2.cs
     文件       15628  2019-02-15 14:03  RSATool\微信截图_20190215140253.png
     目录           0  2019-02-15 14:03  RSATool\

评论

共有 条评论