Exemple #1
0
        public void DisplaySecondaryUploadedPhotos()
        {
            string watermarkText = "© F2-ASPJ";

            //Get the file name.
            string fileName = Path.GetFileNameWithoutExtension(FileUploadMain.PostedFile.FileName) + ".png";

            //Read the File into a Bitmap.
            using (Bitmap bmp = new Bitmap(FileUploadMain.PostedFile.InputStream, false))
            {
                using (Graphics grp = Graphics.FromImage(bmp))
                {
                    //Set the Color of the Watermark text.
                    Brush brush = new SolidBrush(Color.Red);

                    //Set the Font and its size.
                    Font font = new System.Drawing.Font("Arial", 30, FontStyle.Bold, GraphicsUnit.Pixel);

                    //Determine the size of the Watermark text.
                    SizeF textSize = new SizeF();
                    textSize = grp.MeasureString(watermarkText, font);

                    //Position the text and draw it on the image.
                    Point position = new Point((bmp.Width - ((int)textSize.Width + 10)), (bmp.Height - ((int)textSize.Height + 10)));
                    grp.DrawString(watermarkText, font, brush, position);

                    //Embedding secretText into ImageMain

                    Bitmap WatermarkedImageSec = bmp;
                    secretTextSec         = Cryptography.GetRandomString();
                    secretTextKeySec      = Cryptography.GetRandomString();
                    encrytedSecretTextSec = EncryptStringAesIntoImage(secretTextSec, secretTextKeySec);
                    WatermarkedImageSec   = Cryptography.embedText(encrytedSecretTextSec, WatermarkedImageSec);

                    ViewState["secretTextKeySec"]      = secretTextKeySec;
                    ViewState["encrytedSecretTextSec"] = encrytedSecretTextSec;

                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        //Save the Watermarked image to the MemoryStream.
                        WatermarkedImageSec.Save(memoryStream, ImageFormat.Png);
                        //Save image
                        uniqueFileNameSec = Path.ChangeExtension(FileUploadMain.FileName, DateTime.Now.Ticks.ToString());
                        ViewState["uniqueFileNameSec"] = uniqueFileNameSec;
                        string SecTargetPath = Path.Combine(photoFolderSec, uniqueFileNameSec + extensionSec);
                        WatermarkedImageSec.Save(SecTargetPath, WatermarkedImageSec.RawFormat);

                        //Displaying of image
                        Byte[] bytes = memoryStream.ToArray();
                        ViewState["filesizeSec"] = bytes.Length.ToString();
                        string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
                        SecondaryUploadedImage.ImageUrl = "data:image/png;base64," + base64String;
                        SecondaryUploadedImage.Visible  = true;
                        SecondaryUploadedImage.Width    = 150;
                        SecondaryUploadedImage.Height   = 150;
                        StatusLabelMain.Visible         = true;
                    }
                }
            }
        }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string idFromPrevious = Cryptography.DecryptUrl(HttpUtility.UrlDecode(Request.QueryString["23rewwr343wd9jfsk23dmjd2q33c3g"]));

            galleryID = Int32.Parse(idFromPrevious);

            //SecretText Generate
            //if (ViewState["StoredText"] == null)
            //{
            //    secretEncryptionKey = Cryptography.GetRandomString();
            //}
            //else
            //{
            //    secretEncryptionKey = (string)ViewState["StoredText"];
            //}
            //Encrypt of secret text in image of Main
            if (ViewState["StoredIdMain"] == null)
            {
                randomPicIDMain = Cryptography.GetRandomString();
            }
            else
            {
                randomPicIDMain = (string)ViewState["StoredIdMain"];
            }
            //Encrypt of secret text in image of Sec
            if (ViewState["StoredIdSec"] == null)
            {
                randomPicIDSec = Cryptography.GetRandomString();
            }
            else
            {
                randomPicIDSec = (string)ViewState["StoredIdSec"];
            }

            using (SqlConnection connection = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["F2DatabaseConnectionString"].ConnectionString))
            {
                SqlDataReader reader;
                SqlCommand    cmd = new SqlCommand();
                cmd.CommandText = "SELECT [DesignName],[Cost],[CategoryID] FROM [dbo].[Gallery] WHERE [GalleryID]= @GalleryID AND [UserID] = @UserID;";
                cmd.Parameters.AddWithValue("GalleryID", galleryID);
                cmd.Parameters.AddWithValue("UserID", userid);
                cmd.Connection = connection;
                connection.Open();
                cmd.ExecuteNonQuery();

                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    title      = reader.GetString(0);
                    amount     = reader.GetInt32(1);
                    categoryID = reader.GetInt32(2);
                }
                connection.Close();

                SqlCommand cmd2 = new SqlCommand();
                cmd2.CommandText = "SELECT [CategoryName] FROM [dbo].[Category] WHERE [CategoryID]= @CategoryID;";
                cmd2.Parameters.AddWithValue("CategoryID", categoryID);
                cmd2.Connection = connection;
                connection.Open();
                cmd2.ExecuteNonQuery();

                reader = cmd2.ExecuteReader();
                while (reader.Read())
                {
                    categoryName = reader.GetString(0);
                }
                connection.Close();
            }
            this.DesignTitleLabel.Text = title;
            this.CategoryLabel.Text    = categoryName;
            this.CostLabel.Text        = "$" + amount.ToString();
            this.SellerLabel.Text      = userid;
        }
Exemple #3
0
        protected void btnPreviewMain_Click(object sender, EventArgs e)
        {
            //Storage of database essentials
            ViewState["filesizeMain"]  = FileUploadMain.PostedFile.ContentLength.ToString();
            ViewState["medianameMain"] = FileUploadMain.PostedFile.FileName;
            //filesizeMain = FileUploadMain.PostedFile.ContentLength.ToString();
            //medianameMain = FileUploadMain.PostedFile.FileName;

            extensionMain = Path.GetExtension(FileUploadMain.FileName);
            extensionSec  = Path.GetExtension(FileUploadMain.FileName);
            ViewState["extensionMain"] = extensionMain;
            ViewState["extensionSec"]  = extensionSec;
            if (FileUploadMain.HasFile)
            {
                try
                {
                    if (FileUploadMain.PostedFile.ContentType == "image/png" || FileUploadMain.PostedFile.ContentType == "text/plain")
                    {
                        if (FileUploadMain.PostedFile.ContentLength < 1000000)
                        {
                            photoFolderMain           = Path.Combine(fromRootToPhotosMain, randomPicIDMain);
                            ViewState["StoredIdMain"] = randomPicIDMain;

                            photoFolderSec           = Path.Combine(fromRootToPhotosSec, randomPicIDSec);
                            ViewState["StoredIdSec"] = randomPicIDSec;
                            //Main Create Dir
                            if (!Directory.Exists(photoFolderMain))
                            {
                                Directory.CreateDirectory(photoFolderMain);
                            }
                            //Sec Create Dir
                            if (!Directory.Exists(photoFolderSec))
                            {
                                Directory.CreateDirectory(photoFolderSec);
                            }
                            ViewState["PhotoFolderMain"]    = photoFolderMain;
                            ViewState["PhotoFolderSec"]     = photoFolderSec;
                            uniqueFileNameMain              = Path.ChangeExtension(FileUploadMain.FileName, DateTime.Now.Ticks.ToString());
                            ViewState["uniqueFileNameMain"] = uniqueFileNameMain;

                            //Editing of main image
                            //Stream strm = FileUploadMain.PostedFile.InputStream;
                            //string targetPath;
                            //using (var img = System.Drawing.Image.FromStream(strm))
                            //{
                            //    int newWidth = 240;
                            //    int newHeight = 240;
                            //    var thumbImg = new Bitmap(newWidth, newHeight);
                            //    var thumbGraph = Graphics.FromImage(thumbImg);
                            //    thumbGraph.CompositingQuality = CompositingQuality.HighQuality;
                            //    thumbGraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
                            //    thumbGraph.SmoothingMode = SmoothingMode.HighQuality;
                            //    var imgRectangle = new Rectangle(0, 0, newWidth, newHeight);
                            //    thumbGraph.DrawImage(img, imgRectangle);

                            //    targetPath = photoFolderMain + randomPicIDMain + "\\" + uniqueFileNameMain;
                            //    using (Bitmap bmp = new Bitmap(thumbImg))
                            //    {
                            //        bmp.Save(targetPath ,bmp.RawFormat);
                            //    }
                            //}

                            //Embedding secretText into ImageMain
                            Stream strm = FileUploadMain.PostedFile.InputStream;
                            Bitmap WatermarkedImageMain = (Bitmap)Image.FromStream(strm);
                            secretTextMain         = Cryptography.GetRandomString();
                            secretTextKeyMain      = Cryptography.GetRandomString();
                            encrytedSecretTextMain = EncryptStringAesIntoImage(secretTextMain, secretTextKeyMain);
                            WatermarkedImageMain   = Cryptography.embedText(encrytedSecretTextMain, WatermarkedImageMain);
                            WatermarkedImageMain.Save(Path.Combine(photoFolderMain, uniqueFileNameMain + extensionMain));

                            ViewState["secretTextKeyMain"]      = secretTextKeyMain;
                            ViewState["encrytedSecretTextMain"] = encrytedSecretTextMain;

                            var clam       = new ClamClient("localhost", 3310);
                            var scanResult = clam.ScanFileOnServer(Path.Combine(photoFolderMain, uniqueFileNameMain + extensionMain));

                            switch (scanResult.Result)
                            {
                            case ClamScanResults.Clean:
                                StatusLabelMain.CssClass = "label label-success";
                                StatusLabelMain.Text     = "Upload status: File uploaded!";
                                DisplayMainUploadedPhotos(imageToByteArray(WatermarkedImageMain));
                                DisplaySecondaryUploadedPhotos();

                                break;

                            case ClamScanResults.VirusDetected:
                                StatusLabelMain.Text = "Upload status: Virus Found!!!!!";
                                File.Delete(Path.Combine(photoFolderMain, uniqueFileNameMain + extensionMain));
                                StatusLabelMain.CssClass = "label label-danger";
                                break;

                            case ClamScanResults.Error:
                                StatusLabelMain.Text = scanResult.RawResult;
                                File.Delete(Path.Combine(photoFolderMain, uniqueFileNameMain + extensionMain));
                                StatusLabelMain.CssClass = "label label-danger";
                                break;
                            }
                        }
                        else
                        {
                            StatusLabelMain.Text     = "Upload status: The file has to be less than 1 MB!";
                            StatusLabelMain.CssClass = "label label-danger";
                        }
                    }
                    else
                    {
                        StatusLabelMain.Text     = "Upload status: Only PNG Or BMP files are accepted!";
                        StatusLabelMain.CssClass = "label label-danger";
                    }
                }
                catch (Exception ex)
                {
                    StatusLabelMain.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                }
            }
            else
            {
                StatusLabelMain.Text     = "Upload status: You have not chosen a picture to preview!!";
                StatusLabelMain.CssClass = "label label-danger";
            }
        }