public void LoginUser() { SomethingsHereEntities entities = new SomethingsHereEntities(); LoginUser user = new LoginUser(); user.Answer = "Answer"; user.CreatedDate = DateTime.Now; user.Email = "*****@*****.**"; user.IsActive = true; user.Password = CryptoManager.Encrypt("123"); //user.Password = CryptoManager.Decrypt(user.Password); //sifreleme aes kullanılır public ve private key vardır user.Question = "Question"; user.Username = "******"; entities.LoginUser.Add(user); entities.SaveChanges(); LoginUserDetail loginUserDetail = new LoginUserDetail(); loginUserDetail.ID = user.ID; loginUserDetail.DeliveryAddress = "İzmir"; loginUserDetail.Fullname = "Mehmet Aydın Kıcırtı"; loginUserDetail.Gender = /*Convert.ToInt32(E_Gender.Male);*/ (int)E_Gender.Male; loginUserDetail.InvoiceAddress = "İzmir"; loginUserDetail.Phone = "0544083044"; entities.LoginUserDetail.Add(loginUserDetail); entities.SaveChanges(); }
public async Task <IActionResult> Post(string url) { var service = new PostService(); var post = await service.GetPost(url); UserCookieData data = Deserialize(_crypto.Decrypt(HttpContext.Request.Cookies[userCookieId])); if ((DateTime.UtcNow - data.LastAccessed).TotalHours > 12) { data = new UserCookieData(); } if (!data.ViewedPostIds.Contains(post.Id)) { data.ViewedPostIds.Add(post.Id); string encryptedCookie = _crypto.Encrypt(GetJson(data.ViewedPostIds)); HttpContext.Response.Cookies.Delete(userCookieId); HttpContext.Response.Cookies.Append(userCookieId, encryptedCookie, new CookieOptions() { Expires = DateTimeOffset.Now.AddHours(24) }); new IncrementPostViewCount().HandleAsync(post.Id); } ViewBag.Title = post.Title + " - YouIT"; if (post.Text.Length > 135) { ViewBag.MetaDescription = post.Text.Substring(0, 135).Replace("<p>", "").Replace("</p>", "") + "..."; } //TODO: introduce UI services layer and move it to there and refactor //if (HttpContext.User.Identity.IsAuthenticated) //{ // string userId = UserId; // foreach (var comment in post.Comments) // { // if (comment.WhoLiked.Contains(userId)) // comment.UserReaction = UserReaction.Liked; // else if (comment.WhoDisliked.Contains(userId)) // comment.UserReaction = UserReaction.Disliked; // else comment.UserReaction = UserReaction.None; // foreach (var answer in comment.Answers) // { // if (answer.WhoLiked.Contains(userId)) // answer.UserReaction = UserReaction.Liked; // else if (answer.WhoDisliked.Contains(userId)) // answer.UserReaction = UserReaction.Disliked; // else answer.UserReaction = UserReaction.None; // } // } //} return(View(post)); }
/// <summary> /// Encrypes the connection string. One time use /// </summary> /// <param name="dbConnectSting"></param> /// <returns></returns> private static string EncryptDBConnStr(string dbConnectString) { CryptoManager crypto = new CryptoManager(CryptoType.Rijndael, CryptoKey, CryptoIV); crypto.Encrypt(ref dbConnectString); return(dbConnectString); }
public static PackFileHeaderVer2 CreateHeader(int index, Encryption dwFlag, ulong offset, byte[] data) { CryptoManager.Encrypt(PackVersion.NS2F, data, dwFlag, out uint size, out uint compressedSize, out uint encodedSize); return(new PackFileHeaderVer2 { BufferFlag = dwFlag, FileIndex = index, EncodedFileSize = encodedSize, CompressedFileSize = compressedSize, FileSize = size, Offset = offset }); }
public static PackFileHeaderVer3 CreateHeader(PackVersion version, int index, Encryption flag, ulong offset, byte[] data) { CryptoManager.Encrypt(version, data, flag, out uint size, out uint compressedSize, out uint encodedSize); return(new PackFileHeaderVer3(version) { BufferFlag = flag, FileIndex = index, EncodedFileSize = encodedSize, CompressedFileSize = compressedSize, FileSize = size, Offset = offset }); }
public FileContentResult ImageValidator() { Response.Cache.SetCacheability(HttpCacheability.NoCache); VerifyImage v = new VerifyImage(); string code = v.CreateVerifyCode(); CookieHelper.SaveCookie <String>("VerifyCode", code); using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) { Bitmap image = v.CreateImageCode(code); image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); code = CryptoManager.Encrypt(code.ToUpper()); byte[] b = ms.GetBuffer(); return(File(b, @"image/jpg")); } }
/// <summary> /// Perform bytes encryption before each send to client. /// </summary> /// <param name="incomingBytes">incomming bytes</param> /// <returns>encrypted bytes</returns> private byte[] EncryptPacket(IPacketStream packet) { var rawBytes = packet.Buffer; byte[] temp = new byte[rawBytes.Length - 2]; // Skip 2 bytes, because it's packet size and we should not encrypt them. Array.Copy(rawBytes, 2, temp, 0, rawBytes.Length - 2); // Calculated encrypted bytes. var encryptedBytes = CryptoManager.Encrypt(temp); var resultBytes = new byte[rawBytes.Length]; // Copy packet length. resultBytes[0] = rawBytes[0]; resultBytes[1] = rawBytes[1]; // Copy encrypted bytes. for (var i = 0; i < encryptedBytes.Length; i++) { resultBytes[i + 2] = encryptedBytes[i]; } return(resultBytes); }
static HttpResponse RequestHandler(HttpRequest req) { DateTime startTime = DateTime.Now; HttpResponse resp = null; bool connAdded = false; try { #region Unauthenticated-APIs switch (req.Method) { case HttpMethod.GET: if (WatsonCommon.UrlEqual(req.RawUrlWithoutQuery, "/loopback", false)) { resp = new HttpResponse(req, true, 200, null, "application/json", "Hello from CryptoServer!", false); return(resp); } break; case HttpMethod.PUT: case HttpMethod.POST: case HttpMethod.DELETE: default: break; } #endregion #region Add-to-Connection-List _Connections.Add(Thread.CurrentThread.ManagedThreadId, req); connAdded = true; #endregion #region APIs if (!String.IsNullOrEmpty(req.RetrieveHeaderValue(_Settings.Auth.ApiKeyHeader))) { if (req.RetrieveHeaderValue(_Settings.Auth.ApiKeyHeader).Equals(_Settings.Auth.AdminApiKey)) { #region Admin-API-Key _Logging.Log(LoggingModule.Severity.Info, "RequestHandler use of admin API key detected for: " + req.RawUrlWithoutQuery); switch (req.Method) { case HttpMethod.GET: if (WatsonCommon.UrlEqual(req.RawUrlWithoutQuery, "/_cryptoserver/connections", false)) { resp = new HttpResponse(req, true, 200, null, "application/json", _Connections.GetActiveConnections(), false); return(resp); } if (WatsonCommon.UrlEqual(req.RawUrlWithoutQuery, "/_cryptoserver/config", false)) { resp = new HttpResponse(req, true, 200, null, "application/json", _Settings, false); return(resp); } break; case HttpMethod.PUT: case HttpMethod.POST: case HttpMethod.DELETE: default: break; } _Logging.Log(LoggingModule.Severity.Warn, "RequestHandler unknown admin API endpoint: " + req.RawUrlWithoutQuery); resp = new HttpResponse(req, false, 400, null, "application/json", "Unknown API endpoint or verb", false); return(resp); #endregion } else if (req.RetrieveHeaderValue(_Settings.Auth.ApiKeyHeader).Equals(_Settings.Auth.CryptoApiKey)) { #region Crypto-API-Key string failureReason; byte[] responseData; Obj responseObj; switch (req.Method) { case HttpMethod.POST: if (WatsonCommon.UrlEqual(req.RawUrlWithoutQuery, "/decrypt", false)) { Obj reqObj = Common.DeserializeJson <Obj>(req.Data); if (!_Crypto.Decrypt(reqObj, out responseData, out failureReason)) { _Logging.Log(LoggingModule.Severity.Warn, "RequestHandler unable to decrypt: " + failureReason); resp = new HttpResponse(req, false, 500, null, "application/json", failureReason, false); return(resp); } else { _Logging.Log(LoggingModule.Severity.Debug, "RequestHandler encrypt returning " + responseData.Length + " bytes"); resp = new HttpResponse(req, true, 200, null, "application/octet-stream", responseData, true); return(resp); } } if (WatsonCommon.UrlEqual(req.RawUrlWithoutQuery, "/encrypt", false)) { if (!_Crypto.Encrypt(req.Data, out responseObj, out failureReason)) { _Logging.Log(LoggingModule.Severity.Warn, "RequestHandler unable to encrypt: " + failureReason); resp = new HttpResponse(req, false, 500, null, "application/json", failureReason, false); return(resp); } else { resp = new HttpResponse(req, true, 200, null, "application/json", Common.SerializeJson(responseObj), true); return(resp); } } break; case HttpMethod.GET: case HttpMethod.PUT: case HttpMethod.DELETE: default: break; } _Logging.Log(LoggingModule.Severity.Warn, "RequestHandler unknown crypto API endpoint: " + req.RawUrlWithoutQuery); resp = new HttpResponse(req, false, 400, null, "application/json", "Unknown API endpoint or verb", false); return(resp); #endregion } else { #region Invalid-Auth-Material _Logging.Log(LoggingModule.Severity.Warn, "RequestHandler invalid API key supplied: " + req.RetrieveHeaderValue(_Settings.Auth.ApiKeyHeader)); resp = new HttpResponse(req, false, 401, null, "application/json", "Invalid API key", false); return(resp); #endregion } } resp = new HttpResponse(req, false, 401, null, "application/json", "No authentication material", false); return(resp); #endregion } catch (Exception e) { _Logging.LogException("CryptoServer", "RequestHandler", e); resp = new HttpResponse(req, false, 500, null, "application/json", "Internal server error", false); return(resp); } finally { if (resp != null) { string message = "RequestHandler " + req.SourceIp + ":" + req.SourcePort + " " + req.Method + " " + req.RawUrlWithoutQuery; message += " " + resp.StatusCode + " " + Common.TotalMsFrom(startTime) + "ms"; _Logging.Log(LoggingModule.Severity.Debug, message); } if (connAdded) { _Connections.Close(Thread.CurrentThread.ManagedThreadId); } } }
public LoginUser CheckLogin(string username, string password) { password = CryptoManager.Encrypt(password); return(Db.LoginUser.Where(p => p.Username == username && p.Password == password).SingleOrDefault()); }
public XmlDocument Serialize([CanBeNull] string encryptionKey) { Assert.IsNotNullOrEmpty(this.Server, "Server"); Assert.IsNotNullOrEmpty(this.List, "List"); Assert.IsNotNullOrEmpty(this.TemplateID, "TemplateID"); var xmlDocument = new XmlDocument(); XmlNode rootNode = xmlDocument.CreateElement(RootNodeName); xmlDocument.AppendChild(rootNode); XmlNode node = xmlDocument.CreateElement(ServerNodeName); node.InnerXml = this.Server; rootNode.AppendChild(node); if (!string.IsNullOrEmpty(this.Web)) { node = xmlDocument.CreateElement(WebNodeName); node.InnerXml = this.Web; rootNode.AppendChild(node); } node = xmlDocument.CreateElement(ListNodeName); node.InnerXml = this.List; rootNode.AppendChild(node); if (!string.IsNullOrEmpty(this.Folder)) { node = xmlDocument.CreateElement(FolderNodeName); node.InnerXml = this.Folder; rootNode.AppendChild(node); } if (!string.IsNullOrEmpty(this.View)) { node = xmlDocument.CreateElement(ViewNodeName); node.InnerXml = this.View; rootNode.AppendChild(node); } var credentials = this.Credentials as NetworkCredential; if (credentials != null) { Assert.IsNotNullOrEmpty(encryptionKey, "Integration Config Data that contains credentials could not be serialized without encryption key."); string userName = credentials.UserName; string domain = credentials.Domain; if (!string.IsNullOrEmpty(domain)) { userName = StringUtil.EnsurePostfix('\\', domain) + userName; } node = xmlDocument.CreateElement(UserNameNodeName); node.InnerXml = userName; rootNode.AppendChild(node); node = xmlDocument.CreateElement(PasswordNodeName); node.InnerXml = CryptoManager.Encrypt(credentials.Password, encryptionKey); rootNode.AppendChild(node); } if (this.ItemLimit > 0) { node = xmlDocument.CreateElement(ItemLimitNodeName); node.InnerXml = this.ItemLimit.ToString(); rootNode.AppendChild(node); } if (this.ExpirationInterval > 0) { node = xmlDocument.CreateElement(ExpirationIntervalNodeName); node.InnerXml = this.ExpirationInterval.ToString(); rootNode.AppendChild(node); } node = xmlDocument.CreateElement(TemplateIDNodeName); node.InnerXml = this.TemplateID; rootNode.AppendChild(node); if (this.FieldMappings.Count > 0) { XmlNode fieldMappingsNode = xmlDocument.CreateElement(FieldMappingsNodeName); rootNode.AppendChild(fieldMappingsNode); foreach (FieldMapping fieldMapping in this.FieldMappings) { XmlNode fieldMappingNode = xmlDocument.ImportNode(fieldMapping.Serialize(), true); fieldMappingsNode.AppendChild(fieldMappingNode); } } if (!string.IsNullOrEmpty(this.ConnectionConfiguration)) { node = xmlDocument.CreateElement(ConnectionConfigurationNodeName); node.InnerXml = this.ConnectionConfiguration; rootNode.AppendChild(node); } return(xmlDocument); }
/// <summary> /// 修改礼品卡密码 /// </summary> /// <param name="code">卡号</param> /// <param name="pwd">新密码</param> public static void ModifyGiftCardPwd(string code, string pwd) { pwd = CryptoManager.Encrypt(pwd);//加密 GiftCardDA.ModifyGiftCardPwd(code, pwd); }
/// <summary> /// 通过卡号和密码加载礼品卡 /// </summary> /// <param name="code">卡号</param> /// <param name="password">密码</param> /// <returns>礼品卡信息</returns> public static GiftCardInfo LoadGiftCard(string code, string password) { password = CryptoManager.Encrypt(password);//加密比对 return(GiftCardDA.LoadGiftCard(code, password)); }
public static string Encrypt(this string chipperText, string encryptionKey = "") { return(CryptoManager.Encrypt(chipperText, encryptionKey)); }