//using Common; namespace WX.CRM.Common.BlowFish { public class BlowFish { public static string BlowFishKey = "upchina6"; //Common.Utility.GetSettingByKey("BlowFishKey"); public static string BlowFishIV = "upchina1";// Common.Utility.GetSettingByKey("BlowFishIV"); public static string encode(string authInfohqRights) { var iv = System.Text.Encoding.UTF8.GetBytes(BlowFishIV); var blowFish = new SMVC.Tool.BlowfishSimple(BlowFishKey, iv); return blowFish.Encrypt(authInfohqRights, iv); } //public static bool isBlowFish(string authInfoid, string authInfohqRights) //{ // bool isbool = false; // try // { // if (!string.IsNullOrEmpty(authInfoid) && !string.IsNullOrEmpty(authInfohqRights)) // { // authInfoid = HttpUtility.UrlDecode(authInfoid); // authInfohqRights = HttpUtility.UrlDecode(authInfohqRights); // if (!string.IsNullOrEmpty(BlowFishKey) && !string.IsNullOrEmpty(BlowFishIV)) // { // SMVC.Tool.BlowfishSimple blowFish = new SMVC.Tool.BlowfishSimple(BlowFishKey, System.Text.Encoding.UTF8.GetBytes(BlowFishIV)); // string new_authInfohqRights = blowFish.Decrypt(authInfohqRights); // if (new_authInfohqRights != null) // { // try // { // AuthInfohqRights objAuthInfohqRights = Common.JsonHelper.JsonDivertToObj(new_authInfohqRights); // if (objAuthInfohqRights != null) // { // blowFish = new SMVC.Tool.BlowfishSimple(objAuthInfohqRights.rd, System.Text.Encoding.UTF8.GetBytes(BlowFishIV)); // string new_authInfoid = blowFish.Decrypt(authInfoid); // if (new_authInfoid != null) // { // if (new_authInfoid.Trim() == objAuthInfohqRights.uid.Trim()) // { // isbool = true; // } // } // } // } // catch { } // } // } // } // } // catch { } // return isbool; //} //public static string Check(string authInfoid, string authInfohqRights) //{ // ResponseResult rr = new ResponseResult(); // if (string.IsNullOrEmpty(authInfoid) || string.IsNullOrEmpty(authInfohqRights)) // { // rr.code = 0; // rr.errmsg = "authInfoid或者authInfohqRights为空"; // } // else // { // authInfoid = HttpUtility.UrlDecode(authInfoid); // authInfohqRights = HttpUtility.UrlDecode(authInfohqRights); // //string BlowFishKey = Common.Utility.GetSettingByKey("BlowFishKey"); // //string BlowFishIV = Common.Utility.GetSettingByKey("BlowFishIV"); // if (string.IsNullOrEmpty(BlowFishKey) || string.IsNullOrEmpty(BlowFishIV)) // { // rr.code = -5; // rr.errmsg = "系统错误"; // } // else // { // SMVC.Tool.BlowfishSimple blowFish = new SMVC.Tool.BlowfishSimple(BlowFishKey, System.Text.Encoding.UTF8.GetBytes(BlowFishIV)); // string new_authInfohqRights = blowFish.Decrypt(authInfohqRights); // if (new_authInfohqRights == null) // { // rr.code = -4; // rr.errmsg = "authInfohqRights 有误"; // } // else // { // try // { // AuthInfohqRights objAuthInfohqRights = Common.JsonHelper.JsonDivertToObj(new_authInfohqRights); // if (objAuthInfohqRights == null) // { // rr.code = -2; // rr.errmsg = "解析返回NULL"; // } // else // { // blowFish = new SMVC.Tool.BlowfishSimple(objAuthInfohqRights.rd, System.Text.Encoding.UTF8.GetBytes(BlowFishIV)); // string new_authInfoid = blowFish.Decrypt(authInfoid); // if (new_authInfoid == null) // { // rr.code = -4; // rr.errmsg = "authInfoid 有误"; // } // else // { // if (new_authInfoid.Trim() == objAuthInfohqRights.uid.Trim()) // { // rr.code = 1; // rr.errmsg = "成功"; // } // else // { // rr.code = -3; // rr.errmsg = "不匹配"; // } // } // } // } // catch (Exception e) // { // rr.code = -1; // rr.errmsg = e.Message; // } // } // } // } // return(Common.JsonHelper.JsonSerializer(rr)); //} public class ResponseResult { public int code { get; set; } public string errmsg { get; set; } //1 成功 //0 authInfoid或者authInfohqRights为空 //-1 解析异常 //-2 解析返回NULL //-3 不匹配 //-4 字符有误 //-5 BlowFishKey或者BlowFishIV为空 } public class AuthInfohqRights { public string uid { get; set; } public string cid { get; set; } public string t { get; set; } public string rd { get; set; } public string u { get; set; } public string r { get; set; } } } }