• 大小: 3.08MB
    文件类型: .7z
    金币: 1
    下载: 0 次
    发布日期: 2023-11-11
  • 语言: C#
  • 标签: 微信  企业付款  C#  

资源简介

// 加载公钥 RsaKeyParameters pubkey; using (var sr = new StreamReader(ConfigurationManager.AppSettings["PubKey"])) { var pemReader = new Org.BouncyCastle.OpenSsl.PemReader(sr); pubkey = (RsaKeyParameters)pemReader.ReadObject(); } // 初始化cipher var cipher = (BufferedAsymmetricBlockCipher)CipherUtilities.GetCipher("RSA/ECB/OAEPWITHSHA-1ANDMGF1PADDING"); cipher.Init(true, pubkey); // 加密message var message = Encoding.UTF8.GetBytes(EncryptString); var output = EncryptUtil.Encrypt(message, cipher); R = Convert.ToBase64String(output);

资源截图

代码片段和文件信息

using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

public class Account
{

    /// 
    /// 订单确认消费之后平台打钱到商家银行卡
    /// 

    /// 
    public void OrderConfirm(int ID)
    {
        PayToUser pay = PayOrderUtil.GetPayToUser();
        try
        {
            /*加密银行卡号和用户姓名*/
            pay.enc_bank_no = RSAEncrypt(pay.enc_bank_no);
            pay.enc_true_name = RSAEncrypt(pay.enc_true_name);
            PayToUser(pay);
        }
        catch (Exception ex)
        {
            //Log4Helper.LogInfo(“PayLogger“ ex.Message ex);
        }
    }

    public string GetPublicKey()
    {

        SortedDictionaryject> di = new SortedDictionaryject>();
        di.Add(“mch_id“ Config.merchant_no);
        di.Add(“nonce_str“ WeChatUtil.getNoncestr());
        di.Add(“sign_type“ “MD5“);
        di.Add(“sign“ WeChatUtil.CreateSign(di Config.pay_secret));
        var data = WeChatUtil.WeChatSignxml(di);
        string result = WeChatUtil.WxCerHttpPost(“https://fraud.mch.weixin.qq.com/risk/getpublickey“ data Config.WeChatCre Config.merchant_no);
        if (!string.IsNullOrWhiteSpace(result))
        {
            //Log4Helper.LogInfo(“PayLogger“ result);
            var returnxml = xmlUtil.xmlToObect(result);
            if (returnxml.return_code == “SUCCESS“)
            {
                if (returnxml.result_code == “SUCCESS“)
                {
                    return returnxml.pub_key;
                }
            }
        }
        return ““;
    }

    public string RSAEncrypt(string EncryptString)
    {
        if (!File.Exists(Config.PubKey))
        {
            var PublicKey = GetPublicKey();
            if (!string.IsNullOrWhiteSpace(PublicKey))
            {
                File.WriteAllText(Config.PubKey PublicKey);
            }
            else
                return “获取公钥失败!“;
        }
        string R;
        // 加载公钥
        RsaKeyParameters pubkey;
        using (var sr = new StreamReader(Config.PubKey))
        {
            var pemReader = new Org.BouncyCastle.OpenSsl.PemReader(sr);
            pubkey = (RsaKeyParameters)pemReader.Readobject();
        }

        // 初始化cipher
        var cipher = (BufferedAsymmetricBlockCipher)CipherUtilities.GetCipher(“RSA/ECB/OAEPWITHSHA-1ANDMGF1PADDING“);
        cipher.Init(true pubkey);

        // 加密message
        var message = Encoding.UTF8.GetBytes(EncryptString);
        var output = EncryptUtil.Encrypt(message cipher);
        R = Convert.Tobase64String(output);
        return R;
    }

    private static void PayToUser(PayToUser pay)
    {
        /*1.生成签名*/
        SortedDictionaryject> dics = new SortedDictionaryject>();
        dics.Add(“mch_id

评论

共有 条评论