[WebMethod]//会员注册 public string register(string account, string pwd, string email) { userinfo item = new userinfo(); item.accounts = HttpUtility.UrlDecode(account); item.pwd = Des.MD5(HttpUtility.UrlDecode(pwd)); item.email = HttpUtility.UrlDecode(email); item.adddate = DateTime.Now; item.atid = 1; Random r = new Random(); int num = r.Next(1, 72); item.headerimg = num.ToString() + ".jpg"; bool result = user.adduser(item); if (result) { string uid = user.getuidbyemail(item); HttpCookie uidcookie = new HttpCookie("tfuid"); uidcookie.Value = uid.ToString(); HttpContext.Current.Response.Cookies.Add(uidcookie); return("t"); } else { return("f"); } }
public JsonResponse FastJson(object data, string token = "", int retCode = 0, string retMsg = "请求成功", int retCnt = 0, string reqHash = "") { try { if (ConfigUtil.Isdebug) { data = data.SerializeObject(); } else { data = Des.Encrypt(data.SerializeObject(), TokenHelper.GetKeyByToken(token, 8)); } return(new JsonResponse() { Code = retCode, Count = retCnt, Msg = retMsg, Data = data }); } catch (Exception ex) { LogHelper.WriteLog(ex, "basecontroller/fastjson"); return(new JsonResponse() { Code = 1, Msg = "程序错误" + ex.Message }); } }
/// <summary> /// One-way transformation. The spec says that the password must be /// padded with blanks, Samba does it iwth 0 ??? /// <para>OWF = Ex(P14, S8)</para> /// </summary> /// <param name = "password">password</param> /// <returns>byte[16]</returns> internal static byte[] GetLmOwf(string password) { var p14 = new byte[14]; password = password.ToUpper(); for (int i = 0; i < password.Length; i++) { p14[i] = (byte)(password[i] & 0xff); } var s16 = new byte[16]; var key7 = new byte[7]; var key8 = new byte[8]; var e8 = new byte[8]; for (int i = 0; i < 2; i++) { Array.Copy(p14, 7 * i, key7, 0, 7); Des.MakeSmbKey(key7, key8); var des = new Des(key8); des.Encrypt(S8, e8); Array.Copy(e8, 0, s16, 8 * i, 8); } return(s16); }
public string GetLogOnUrl(string userName, string password, string cityId, string systemId, string serverId) { string url = ""; string logOnKey = ""; if (string.IsNullOrEmpty(serverId)) { url = GetUrlFromCity(new Guid(cityId), out serverId); } if (string.IsNullOrEmpty(password)) { IQueryable <THOK.Authority.DbModel.User> queryCity = UserRepository.GetQueryable(); var user = queryCity.Single(c => c.UserName == userName); password = user.Pwd; } if (!string.IsNullOrEmpty(serverId)) { url = GetUrlFromServer(new Guid(serverId)); } var key = new UserLoginInfo() { CityID = cityId, SystemID = systemId, UserName = userName, Password = password, ServerID = serverId }; logOnKey = Des.EncryptDES((new JavaScriptSerializer()).Serialize(key), "12345678"); url += @"/Account/LogOn/?LogOnKey=" + Uri.EscapeDataString(logOnKey); return(url); }
/// <summary> /// 服务器用这个方法来检验Web API请求者的身份是否合法 /// </summary> /// <param name="strAuthUser">来自请求包头的Custom-Auth-Name</param> /// <param name="strAuthKey">来自请求包头的Custom-Auth-Key</param> /// <param name="strRequestUri">请求的Uri</param> /// <param name="strPwdMd5TwiceSvr">从数据库中获取到的密码</param> /// <param name="guidRequest">[out]解释出来的请求包GUID,用来防止重发攻击</param> public static bool VerifyAuthKey(string strAuthUser, string strAuthKey, string strRequestUri, string strPwdSvr) { try { string strUrlAndGuid = Des.Decode(strAuthKey, Md5.MD5TwiceEncode(strPwdSvr)); string[] arrUrlAndGuid = strUrlAndGuid.Split(new[] { ' ' }); if (arrUrlAndGuid.Length != 2) { return(false); } string strUrl = arrUrlAndGuid[0]; string strGuid = arrUrlAndGuid[1]; Guid guidRequest = new Guid(strGuid); //判断URL确认身份 strRequestUri = InternalHelper.GetEffectiveUri(strRequestUri); if (string.Compare(Md5.MD5Encode(strRequestUri + guidRequest), strUrl, true) == 0) { return(true); } } catch (Exception) { //Ignore any exception } return(false); }
public JsonResult Get(string id) { try { var result = new QrCodeDTO(); var key = System.Configuration.ConfigurationManager.AppSettings["QrCodeKey"]; var values = Des.DesDecrypt(id, Des.GetLegalKey(key)).Split('|'); string type = values[0]; if (values.Length > 1) { string ID = values[1], version = ""; if (values.Length > 2) { version = values[2]; } var qrcode = ProductService.GetProductDetail(ID, decimal.Parse(version)); qrcode.Type = type; result = qrcode; result.State = true; } else { throw new Exception("系统错误,请联系管理员"); } return(Json(result)); } catch (Exception e) { return(Json(new QrCodeDTO { State = false, Message = e.Message })); } }
public Joueurs(String name) { this.name = name; des = new Des[5]; des[0] = new Des(); des[1] = new Des(); des[2] = new Des(); des[3] = new Des(); des[4] = new Des(); scores = new Dictionary <string, int>(); scores.Add("As", 0); scores.Add("Deux", 0); scores.Add("Trois", 0); scores.Add("Quatre", 0); scores.Add("Cinq", 0); scores.Add("Six", 0); scores.Add("Total", 0); scores.Add("Bonus", -63); scores.Add("Total 1", 0); scores.Add("Brelan", 0); scores.Add("Carre", 0); scores.Add("Full", 0); scores.Add("Petite Suite", 0); scores.Add("Grande Suite", 0); scores.Add("Yams", 0); scores.Add("Chance", 0); scores.Add("Total 2", 0); scores.Add("Total 1 + 2", 0); }
static void Main(string[] args) { // 枚举 Des d = Des.gao | Des.fu; Console.WriteLine(d); Console.ReadKey(); }
public MainWindow() { InitializeComponent(); ILogger logger = new Logger(LogTextBox); des = new Des(logger); CurrentKey = des.GenerateKey(); }
static void Main(string[] args) { string message = "TSITSIRI"; ulong key = 0xF46E986435465354; Des.Encrypt(message, key); }
public IActionResult GrantTicket(AuthRequest request) { Log.Information("Step #3. Received a Ticket Grant request: {@Request}", request); var tgsKey = _keyManager.Keys["tgs"]; if (!_keyManager.Keys.TryGetValue(request.Recepient, out var recepientKey)) { Log.Error("Requested recepient '{Recepient}' was not registered yet", request.Recepient); throw new ArgumentException(); } Log.Information("Step #4.1. Found requested recepient '{Recepient}' in the registered list with key {Key}", request.Recepient, Encoding.UTF8.GetString(recepientKey)); var ticketGrantingTicket = Des.Decrypt <Ticket>(tgsKey, request.EncryptedTicket); Log.Information("Step #4.2. Decrypted the Ticket Granting Ticket using the [AuthServer <-> TGS] key: {@Ticket}", ticketGrantingTicket); var clientToTgsKey = ticketGrantingTicket.Key; Log.Information("Step #4.3. Got a session key ['{Login}' <-> TGS] from TGT: {Key}", ticketGrantingTicket.From, Encoding.UTF8.GetString(ticketGrantingTicket.Key)); var authBlock = Des.Decrypt <AuthBlock>(clientToTgsKey, request.EncryptedAuthBlock); Log.Information("Step #4.4. Decrypted the Auth Block using ['{Login}' <-> TGS] key: {@AuthBlock}", authBlock.Login, authBlock); if (!ticketGrantingTicket.From.Equals(authBlock.Login, System.StringComparison.OrdinalIgnoreCase) || ticketGrantingTicket.Timestamp + ticketGrantingTicket.Expiration < authBlock.Timestamp) { Log.Warning("Names in two blocks are not equal or the TGT has expired"); return(NotFound()); } Log.Information("Step #4.5. Verified the data of two blocks and the ticket expiration time"); var ticket = new Ticket { From = authBlock.Login, To = request.Recepient, Key = KeyManager.GenerateSessionKey(), Timestamp = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds(), Expiration = 300 }; Log.Information("Step #4.6. Build new ticket with newly generated session key [{From} <-> {To}]: {@Ticket}", ticket.From, ticket.To, ticket); var authResponse = new AuthResponse { EncryptedTicket = Des.Encrypt(recepientKey, ticket), Key = ticket.Key }; Log.Information("Step #4.7. Encrypt the ticket using [Auth Server <-> {To}] key and pack it up into the response: {@Response}", ticket.To, authResponse); var encryptedResponse = Des.Encrypt(clientToTgsKey, authResponse); Log.Information("Step #4.8. Encrypt the message before sending using the [{From} <-> TGS] key", ticket.From); return(Ok(Convert.ToBase64String(encryptedResponse))); }
/// <summary> /// 修改密码 /// </summary> /// <param name="ID"></param> /// <param name="password"></param> /// <param name="msg"></param> /// <returns></returns> public static int ChangePwd(decimal ID, string oldPwd, string newPwd, out string msg) { try { using (IDAL dal = DALBuilder.CreateDAL(ConfigurationManager.ConnectionStrings["SYSDB"].ConnectionString, 0)) { dal.BeginTran(); StringBuilder sql = new StringBuilder(256); sql.Append("SELECT UPassword ,UserCode FROM tUser WHERE ID=@ID "); dal.OpenReader(sql.ToString(), dal.CreateParameter("@ID", ID) ); string oldDbPwd, UserCode; if (dal.DataReader.Read()) { oldDbPwd = Convert.ToString(dal.DataReader["UPassword"]).TrimEnd(); UserCode = Convert.ToString(dal.DataReader["UserCode"]).TrimEnd(); } else { msg = "未找到该用户"; return(0); } dal.DataReader.Close(); if (!oldDbPwd.Equals(Des.EncryStrHex(oldPwd, UserCode))) { //密码验证失败 msg = "密码验证失败"; return(0); } sql.Clear(); sql.Append("UPDATE tUser SET UPassword=@UPassword WHERE ID=@ID"); int i; dal.Execute(sql.ToString(), out i, dal.CreateParameter("@UPassword", Des.EncryStrHex(newPwd, UserCode)), dal.CreateParameter("@ID", ID) ); if (i == 1) { dal.CommitTran(); msg = "success"; return(1); } else { dal.RollBackTran(); msg = "error"; return(0); } } } catch (System.Exception ex) { msg = ex.Message; return(-1); } }
/// <summary> /// 保存数据库 /// </summary> /// <param name="db"></param> /// <returns></returns> public static int InsertDatabase(ref Database db, out string msg) { try { using (IDAL dal = DALBuilder.CreateDAL(ConfigurationManager.ConnectionStrings["SYSDB"].ConnectionString, 0)) { StringBuilder sql = new StringBuilder(256); sql.Append(" INSERT INTO tDatabase ( DBCode ,DBType ,DataSource ,DbName ,UserID ,Password ,Remark) "); sql.Append("VALUES ("); sql.Append("@DbCode,@DbType,@DataSource,@DbName,@UserID,@Password,@Remark )"); dal.BeginTran(); int i; dal.Execute(sql.ToString(), out i, dal.CreateParameter("@DbCode", db.DbCode), dal.CreateParameter("@DbType", db.DbType), dal.CreateParameter("@DataSource", db.DataSource), dal.CreateParameter("@DbName", db.DbName), dal.CreateParameter("@UserID", db.UserID), dal.CreateParameter("@Password", Des.EncryStrHex(db.Password, db.UserID)), dal.CreateParameter("@Remark", db.Remark) ); if (i == 1) { sql.Clear(); sql.Append("SELECT IDENT_CURRENT('tDatabase') "); dal.OpenReader(sql.ToString()); if (dal.DataReader.Read()) { db.ID = Convert.ToDecimal(dal.DataReader[0]); dal.DataReader.Close(); } else { dal.DataReader.Close(); dal.RollBackTran(); throw new Exception("获取报表ID失败"); } dal.CommitTran(); msg = "success"; return(1); } else { dal.RollBackTran(); msg = "error"; return(0); } } } catch (Exception ex) { msg = ex.Message; return(-1); } }
public static string DecodeConfidentialMessage(string strEncoded, string strPwdMd5TwiceSvr) { try { return(Des.Decode(strEncoded, strPwdMd5TwiceSvr)); } catch (Exception) { return(null); } }
private static void MakePrincipleHeader(HttpRequestMessage reqMsg, string strUri) { Guid guid = Guid.NewGuid(); strUri = InternalHelper.GetEffectiveUri(strUri); string strToEncrypt = Md5.MD5Encode(strUri + guid) + " " + guid; string strTheAuthKey = Des.Encode(strToEncrypt, Md5.MD5TwiceEncode(Password)); reqMsg.Headers.Add(Consts.HTTP_HEADER_AUTH_USER, UserName); reqMsg.Headers.Add(Consts.HTTP_HEADER_AUTH_KEY, strTheAuthKey); }
/// <summary> /// 增加用户 /// </summary> /// <returns></returns> public static int AddUser(ref User user, out string msg) { try { using (IDAL dal = DALBuilder.CreateDAL(ConfigurationManager.ConnectionStrings["SYSDB"].ConnectionString, 0)) { StringBuilder sql = new StringBuilder(256); sql.Append("insert into tUser(UserCode,UserName,UPassword,IsAdmin,Enabled) "); sql.Append("Values ("); sql.AppendFormat("@UserCode,@UserName,@UPassword,@IsAdmin,@Enabled"); sql.Append(")"); dal.BeginTran(); int i; dal.Execute(sql.ToString(), out i, dal.CreateParameter("@UserCode", user.UserCode), dal.CreateParameter("@UserName", user.UserName), dal.CreateParameter("@UPassword", Des.EncryStrHex(user.UserCode, user.UserCode)), dal.CreateParameter("@IsAdmin", user.IsAdmin ? 1 : 0), dal.CreateParameter("@Enabled", user.Enabled) ); if (i == 1) { sql.Clear(); sql.Append("SELECT IDENT_CURRENT('tUser') "); dal.OpenReader(sql.ToString()); if (dal.DataReader.Read()) { user.ID = Convert.ToInt32(dal.DataReader[0]); dal.DataReader.Close(); } else { dal.DataReader.Close(); dal.RollBackTran(); throw new Exception("获取ID失败"); } dal.CommitTran(); msg = "success"; return(i); } else { msg = "error"; dal.RollBackTran(); return(0); } } } catch (Exception ex) { msg = ex.Message; return(-1); } }
/// <summary> /// 权限验证 /// </summary> /// <returns></returns> public bool IsValid(out string msg) { Password = Des.DecryStrHex(Password, "0125" + UserCode);//解密 if (SQLBaseDAL.State == ConnectionState.Broken || SQLBaseDAL.State == ConnectionState.Closed) { //连接Broken、Closed if (!SQLBaseDAL.Open(out msg))//开启连接 { return(false); } } return(UserDAL.Check(UserCode, Password, out msg)); }
/// <summary> /// 初始化webservice 对象 /// </summary> /// <param name="Url"></param> /// <param name="UserCode"></param> /// <param name="Password"></param> /// <param name="DeptNo"></param> public static void Init(string Url, string UserCode, string Password, string DeptNo) { if (TransClass == null) { TransClass = new Trans.TService.TransService(); TransClass.CSoapHeaderValue = new CSoapHeader(); } TransClass.Url = Url; TransClass.CSoapHeaderValue.UserCode = UserCode; TransClass.CSoapHeaderValue.Password = Des.EncryStrHex(Password, "0125" + UserCode); TransClass.CSoapHeaderValue.DeptNO = DeptNo; TransClass.CSoapHeaderValue.PosNO = PubGlobal.SysConfig.PosNO; }
private static void MakePrincipleHeader(WebRequest reqMsg, string strUri) { Guid guid = Guid.NewGuid();//为每次请求都生成一个不同的标识 strUri = InternalHelper.GetEffectiveUri(strUri); string strToEncrypt = Md5.MD5Encode(strUri + guid) + " " + guid; string strTheAuthKey = Des.Encode(strToEncrypt, Md5.MD5TwiceEncode(Token ?? "")); reqMsg.Headers.Add(Consts.HTTP_HEADER_AUTH_USER, Account); reqMsg.Headers.Add(Consts.HTTP_HEADER_AUTH_KEY, strTheAuthKey); reqMsg.Headers.Add(HttpRequestHeader.AcceptEncoding, "utf-8"); }
/// <summary> /// 初始化令牌 /// </summary> /// <param name="tokenKey"></param> /// <returns></returns> public bool InitToken(string tokenKey) { try { _expireDate = DateTime.Now; _tokenKey = tokenKey; _tokenId = Des.Decrypt(_tokenKey, EncryptKey); return(true); } catch { return(false); } }
//初始化 public static async void InitAsync(Result <XAppInfo> call) { Dictionary <string, string> keys = new Dictionary <string, string>(); keys.Add("Api", "PanGolin_GetSoftInfo"); HttpWebRequest request = GetOkHttpClient(keys); HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync(); if (response.StatusCode == HttpStatusCode.OK) { string body = response.Headers.Get("Result"); call.next(JsonConvert.DeserializeObject <XAppInfo>(Des.DesDecrypt(body, md5.GetKey(request.Headers.Get("Key"))))); } }
//获取商品信息 public static async void GetPage_data(Result <KfkPageData> call, string kfk) { Dictionary <string, string> keys = new Dictionary <string, string>(); keys.Add("Api", "PanGolin_GetPage_data"); keys.Add("Url", kfk); HttpWebRequest request = GetOkHttpClient(keys); HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync(); if (response.StatusCode == HttpStatusCode.OK) { string body = response.Headers.Get("Result"); call.next(JsonConvert.DeserializeObject <KfkPageData>(Des.DesDecrypt(body, md5.GetKey(request.Headers.Get("Key"))))); } }
/// <summary> /// token 加密数据 /// </summary> /// <param name="encrydata"></param> /// <param name="token"></param> /// <returns></returns> public static string TokenEncry(string encrydata, string token) { try { if (string.IsNullOrEmpty(encrydata) || string.IsNullOrEmpty(token)) { return(string.Empty); } string key = GetKeyByToken(token, 8); return(Des.Encrypt(encrydata, key)); } catch { return(string.Empty); } }
//登录 public static async void loginAsync(Result <XLoginInfo> call, string card, string mac) { Dictionary <string, string> keys = new Dictionary <string, string>(); keys.Add("Api", "PanGolin_Verify"); keys.Add("Mac", mac); keys.Add("Code", card); HttpWebRequest request = GetOkHttpClient(keys); HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync(); if (response.StatusCode == HttpStatusCode.OK) { string body = response.Headers.Get("Result"); call.next(JsonConvert.DeserializeObject <XLoginInfo>(Des.DesDecrypt(body, md5.GetKey(request.Headers.Get("Key"))))); } }
[WebMethod]//检查修改的密码 public string checkeditpwd(string pwd, string userid) { userinfo item = new userinfo(); item.pwd = Des.MD5(pwd); item.userid = userid; bool result = user.checkpwd(item); if (result) { return("t"); } else { return("f"); } }
//校验 public static async void CheckAsync(Result <XCheckInfo> call, string Token, bool CheckType, string mac, string card) { Dictionary <string, string> keys = new Dictionary <string, string>(); keys.Add("Api", "PanGolin_Check"); keys.Add("Mac", mac); keys.Add("Token", Token); keys.Add("Code", card); keys.Add("Type", CheckType ? "formal" : "trial"); HttpWebRequest request = GetOkHttpClient(keys); HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync(); if (response.StatusCode == HttpStatusCode.OK) { string body = response.Headers.Get("Result"); call.next(JsonConvert.DeserializeObject <XCheckInfo>(Des.DesDecrypt(body, md5.GetKey(request.Headers.Get("Key"))))); } }
[WebMethod]//email登录 public string emaillogin(string pwd, string email) { userinfo item = new userinfo(); item.pwd = Des.MD5(HttpUtility.UrlDecode(pwd)); item.email = HttpUtility.UrlDecode(email); bool result = user.emaillogin(item); if (result) { string uid = user.getuidbyemail(item); return(uid); } else { return("f"); } }
//创建订单 public static async void Build_order(Result <Build_order_Info> call, int Productid, int Paytype, string Buyertoken, string kfk) { Dictionary <string, string> keys = new Dictionary <string, string>(); keys.Add("Api", "PanGolin_Build_order"); keys.Add("Productid", "" + Productid); keys.Add("Paytype", "" + Paytype); keys.Add("Buyertoken", Buyertoken); keys.Add("Url", kfk); HttpWebRequest request = GetOkHttpClient(keys); HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync(); if (response.StatusCode == HttpStatusCode.OK) { string body = response.Headers.Get("Result"); call.next(JsonConvert.DeserializeObject <Build_order_Info>(Des.DesDecrypt(body, md5.GetKey(request.Headers.Get("Key"))))); } }
[WebMethod]//账号登录 public string userlogin(string pwd, string accounts) { userinfo item = new userinfo(); item.pwd = Des.MD5(HttpUtility.UrlDecode(pwd)); item.accounts = HttpUtility.UrlDecode(accounts); bool result = user.usernamelogin(item); if (result) { string uid = user.getuseridbyusername(item); return(uid); } else { return("f"); } }
internal static void AnalyzeLisense(string license, string serialNo, out string expDate, out string reportNumber) { char[] chars = license.ToCharArray(); char[] date = new char[16]; char[] keys = new char[16]; char[] number = new char[16]; for (int i = 0; i < 16; i++) { date[i] = chars[i * 3]; number[i] = chars[i * 3 + 1]; keys[i] = chars[i * 3 + 2]; } string key = Des.DecryStrHex(new string(keys), serialNo); expDate = Des.DecryStrHex(new string(date), key); reportNumber = Des.DecryStrHex(new string(number), key); }
public static Des LancerDes(int nombreDes) { Des resultat = new Des(); while (nombreDes > 0) { int tirage = Randomizer.Next(1, 6); resultat.AjouteTirage(tirage); nombreDes--; } return resultat; }