/// <summary> /// 接收登录 /// </summary> /// <param name="request"></param> /// <param name="host"></param> public bool AuthorizationCheck(ClientLoginRequest request) { //先验证数据 HashEncryptProvider provider = new HashEncryptProvider(); if (request.Authorization == 0 && SrvSetting.IsAuthorization) { //验证默认授权(CryptoStruct库必须一致) var code = provider.Encrypt(CipherReply.RequestInfo); if (code == request.HashCode) { //验证通过 return(true); } return(false); } else if (request.Authorization == 1 && SrvSetting.IsFileauthorization) { FileStream fs = new FileStream(SrvSetting.AuthorizationFile, FileMode.Open, FileAccess.Read); var result = provider.Encrypt(fs); var code = Convert.ToBase64String(result); if (code == request.HashCode) { //验证通过 return(true); } return(false); } return(false); }
/// <summary> /// 登录 /// </summary> /// <returns></returns> public byte[] LoginSrv() { ClientLoginRequest client = new ClientLoginRequest(); client.ReqTime = DateTime.Now.Ticks; HashEncryptProvider hashEncrypt = new HashEncryptProvider(); if (ClientSetting.IsFileauthorization) { client.Authorization = 1; FileStream fs = new FileStream(ClientSetting.AuthorizationFile, FileMode.Open); client.HashCode = Convert.ToBase64String(hashEncrypt.Encrypt(fs)); } else { client.HashCode = hashEncrypt.Encrypt(CipherReply.RequestInfo); } // byte[] login = StructManager.StructToBytes(client); var r = StructManager.BytesToStruct <ClientLoginRequest>(login); //设置标致位 byte[] req = new byte[login.Length + 1]; req[0] = 1; Array.Copy(login, 0, req, 1, login.Length); return(req); }
/// <summary> /// 默认授权请求 /// </summary> public void Request() { HashEncryptProvider provider = new HashEncryptProvider(); ClientLoginRequest request = new ClientLoginRequest(); request.Version = 1; request.ReqTime = DateTime.Now.Ticks; request.Limit = 0; request.LastTime = 0; request.HashCode = provider.Encrypt(CipherReply.RequestInfo); }
/// <summary> /// 文件授权 /// </summary> /// <param name="file"></param> public void RequestFile(string file) { HashEncryptProvider provider = new HashEncryptProvider(); ClientLoginRequest request = new ClientLoginRequest(); request.Version = 1; request.ReqTime = DateTime.Now.Ticks; request.Limit = 0; FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read); var result = provider.Encrypt(fs); request.HashCode = Convert.ToBase64String(result); }