c#字典排序加密MD5加密
Posted 擅长死循环
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c#字典排序加密MD5加密相关的知识,希望对你有一定的参考价值。
1、字典排序加密
Dictionary<string, string> dic = new Dictionary<string, string>();
//JObject jsonBoyText = null;
//dic.Add("MobileNo", jsonBoyText.GetValue("mobileno")?.ToString().Trim() ?? "");
//dic.Add("PreferentialID", jsonBoyText.GetValue("preferentialid")?.ToString().Trim() ?? "");
//dic.Add("CouponNumber", jsonBoyText.GetValue("couponnumber")?.ToString().Trim() ?? "");
dic.Add("MobileNo", req.MobileNo.Trim());
dic.Add("PreferentialID", req.PreferentialID.Trim());
dic.Add("CouponNumber", req.CouponNumber.ToString());
if(!string.IsNullOrWhiteSpace(req.StoreID))
dic.Add("StoreID", req.StoreID.Trim());
//按字典排序
var vDic = (from objDic in dic orderby objDic.Key ascending select objDic);
StringBuilder str = new StringBuilder();
foreach (KeyValuePair<string, string> kv in vDic)
string pkey = kv.Key;
string pvalue = kv.Value;
str.Append(pkey + "=" + pvalue.Trim() + "&");
//私钥
string strkey = ConfigurationManager.AppSettings["cmccDockingKey"].ToString();
//MD5加密对比
String disStr = str.ToString().ToLower() + "secretkey=" + strkey.ToString();
var md5Str = Common.MD5Encryption.GetCiphertext(disStr.ToLower());
if (md5Str.ToLower() != req.StrSign.ToLower())
throw new Common.MyArgumentException(103);
2、MD5加密
public static string GetCiphertext(string OriginalText)
using (var md5 = MD5.Create())
var result = md5.ComputeHash(Encoding.UTF8.GetBytes(OriginalText));
var strResult = BitConverter.ToString(result);
return strResult.Replace("-", "");
以上是关于c#字典排序加密MD5加密的主要内容,如果未能解决你的问题,请参考以下文章