public void SendBaseMessage(BaseMessage message, IEndPoint endPoint) { if (message.MessageType.ShouldBeEncrypted()) { var client = realClient.ClientsById[message.RealDestinationId]; if (message.MessageType == MessageType.Data && realClient.ClientsById.ContainsKey(message.DestinationId)) { realClient.ClientsById[message.DestinationId].DataBytesSent += message.Payload.Length; } var key = client.MainKey; if (key == null) { realClient.MessageHandler.DisconnectClient(client.Id); throw new DnmpException($"Selected client key is null; Client Id: [{client.Id}]"); } message = new BaseMessage( SymmetricHelper.Encrypt(key, message.SecurityHash.Concat(message.Payload).ToArray()), message.MessageType, message.SourceId, message.DestinationId, message.RealSourceId, message.RealDestinationId, message.Guid, message.MessageFlags ); } if (realClient.ClientsById.ContainsKey(message.RealDestinationId)) { realClient.ClientsById[message.RealDestinationId].BytesSent += message.TotalLength; } SendRawBytes(message.GetBytes(), endPoint); }
private void SetOrderIdCookie(int orderID) { HttpCookie cookie = HttpContext.Current.Request.Cookies[CookieKey] ?? new HttpCookie(CookieKey); string cookieValue; if (StoreSettings.SecureCookie && SymmetricHelper.CanSafelyEncrypt) { cookieValue = SymmetricHelper.Encrypt(orderID.ToString()); } else { cookieValue = orderID.ToString(); } cookie["OrderID"] = cookieValue; HttpContext.Current.Response.Cookies.Add(cookie); }
protected void grdDownloads_ItemDataBound(object sender, DataGridItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { DownloadInfo downloadInfo = (DownloadInfo)e.Item.DataItem; // Product Title Label lblProductTitle = (Label)e.Item.FindControl("lblProductTitle"); lblProductTitle.Text = downloadInfo.ProductTitle; // Allowed Downloads int allowed = downloadInfo.AllowedDownloads; Label lblAllowed = (Label)e.Item.FindControl("lblAllowed"); if (allowed == Null.NullInteger) { lblAllowed.Text = _unlimitedText; } else { allowed = downloadInfo.AllowedDownloads * downloadInfo.Quantity; lblAllowed.Text = allowed.ToString(); } // Downloaded int downloaded = downloadInfo.Downloads; if (downloaded == Null.NullInteger) { downloaded = 0; } Label lblDownloaded = (Label)e.Item.FindControl("lblDownloaded"); lblDownloaded.Text = downloaded.ToString(); // Download link HtmlAnchor lnkDownload = (HtmlAnchor)e.Item.FindControl("lnkDownload"); if (allowed == Null.NullInteger || downloaded < allowed) { lnkDownload.HRef = string.Format(_downloadPath, Server.UrlEncode(SymmetricHelper.Encrypt(downloadInfo.OrderDetailID + "," + UserId))); lnkDownload.Attributes["OnClick"] = _refreshScript; lnkDownload.InnerText = _downloadText; } else { lnkDownload.Visible = false; } } }
private static void SetCartID(int portalID, string cartID, bool secureCookie) { if (!string.IsNullOrEmpty(cartID)) { HttpCookie cartCookie = new HttpCookie(CookieKey(portalID)); if (secureCookie && SymmetricHelper.CanSafelyEncrypt) { cartCookie["CartID"] = SymmetricHelper.Encrypt(cartID); } else { cartCookie["CartID"] = cartID; } HttpContext.Current.Response.Cookies.Add(cartCookie); } else { HttpCookie cartCookie = new HttpCookie(CookieKey(portalID)); cartCookie.Expires = DateTime.Today.AddDays(-100); HttpContext.Current.Response.Cookies.Add(cartCookie); } }
public byte[] GetBytes() { var dataMemoryStream = new MemoryStream(); var dataWriter = new BigEndianBinaryWriter(dataMemoryStream); dataWriter.Write(NewId); var selfBuf = endPointFactory.SerializeEndPoint(NewEndPoint); if (selfBuf.Length > ushort.MaxValue) { throw new DnmpException("buf.Length larger then ushort"); } dataWriter.Write((ushort)selfBuf.Length); dataWriter.Write(selfBuf); dataWriter.Write((ushort)Clients.Count(x => x.Id != NewId)); foreach (var client in Clients) { if (client.Id == NewId) { continue; } dataWriter.Write(client.Id); dataWriter.Write(client.ParentId); var buf = endPointFactory.SerializeEndPoint(client.EndPoint); if (buf.Length > ushort.MaxValue) { throw new DnmpException("buf.Length larger then ushort"); } dataWriter.Write((ushort)buf.Length); dataWriter.Write(buf); dataWriter.Write((ushort)client.CustomData.Length); dataWriter.Write(client.CustomData); } return(SymmetricHelper.Encrypt(key, dataMemoryStream.ToArray())); }