Exemple #1
0
        public void setConfigValues()
        {
            ds       = new DataSet();
            B_upload = new BuisnessUploads();
            SqlParameter[] commandParameters1 = new SqlParameter[2];
            commandParameters1[0] = new SqlParameter();
            commandParameters1[0].ParameterName = "@ProfileName";
            commandParameters1[0].Value         = Session["profileName"].ToString();
            commandParameters1[1] = new SqlParameter();
            commandParameters1[1].ParameterName = "@hidrefprofile";
            commandParameters1[1].Value         = Session["hidrefprofile"].ToString();

            try
            {
                ds = B_upload.GetTokenvalue(strConnString, "usp_GetUploadConfigvalue", commandParameters1);
                if (ds != null && ds.Tables["FileAndTokenInfo"].Rows.Count > 0)
                {
                    sRefProfName    = ds.Tables[0].Rows[0]["RefProfileName"].ToString();
                    sSLUN           = ds.Tables[0].Rows[0]["ShareLocationUserName"].ToString();
                    sSLD            = ds.Tables[0].Rows[0]["ShareLocationDomain"].ToString();
                    sSLP            = ds.Tables[0].Rows[0]["ShareLocationPassword"].ToString();
                    sSFP            = ds.Tables[0].Rows[0]["SRDocumentsShareFolderPath"].ToString();
                    sPwd            = ds.Tables[0].Rows[0]["SRDocumentsShareFolderPath"].ToString();
                    ShareFolderPath = sSFP;
                    sPwd            = CgServices.DecryptData(sSLP);
                }
            }
            catch (Exception ex)
            {
                Elog = new ErrorLogger();
                Elog.WriteToLogFile(ex, "public setConfigValues In renderFile Profile name '" + Session["profileName"].ToString() + "'and hidprofile'" + Session["hidrefprofile"].ToString() + "'", "tokenValue = '" + Session["mytokenvalue"].ToString() + "' and sessionID = '" + Session["mysessionId"].ToString() + "'  ");
                Elog = null;
            }
            B_upload = null;
        }
Exemple #2
0
        public JsonResult SymmetricEncrypt(WebSecurity.Models.EncryptionModel encryption, string ButtonType)
        {
            var result = new EncryptionModel();

            var symEncryption = new SymmetricEncryption();

            SymmetricAlgorithm symAlgo = new AesManaged();

            symAlgo.Padding = PaddingMode.PKCS7;
            var key = string.Empty;
            var iv  = string.Empty;

            if (!string.IsNullOrEmpty(encryption.PrivateKey) && !string.IsNullOrEmpty(encryption.InitializationVector))
            {
                symAlgo.Key = Convert.FromBase64String(encryption.PrivateKey);
                symAlgo.IV  = Convert.FromBase64String(encryption.InitializationVector);
            }
            else
            {
                key = Convert.ToBase64String(symAlgo.Key);
                iv  = Convert.ToBase64String(symAlgo.IV);
            }

            if (ButtonType == "Encrypt")
            {
                var encryptedText = symEncryption.EncryptText(symAlgo, encryption.PlainText);
                result = new EncryptionModel()
                {
                    EncryptedText        = encryptedText,
                    PlainText            = encryption.PlainText,
                    InitializationVector = iv,
                    PrivateKey           = key
                };
            }
            else if (ButtonType == "Decrypt")
            {
                var plainText = symEncryption.DecryptData(symAlgo, encryption.EncryptedText);

                result = new EncryptionModel()
                {
                    EncryptedText        = encryption.EncryptedText,
                    PlainText            = plainText,
                    PrivateKey           = encryption.PrivateKey,
                    InitializationVector = encryption.InitializationVector
                };
            }

            return(Json(result));
        }
Exemple #3
0
        /// <summary>
        ///		Prepares a datasource for execution by setting the URL,
        ///		and the parameter list.
        /// </summary>
        /// <param name="datasource"></param>
        /// <param name="parameterTypes"></param>
        public void InitializeDatasource(IDataSource datasource, DatasourceParameterType[] parameterTypes)
        {
            object parameterValue;
            DatasourceParameterType parameterType;
            string encryptionKey;

            encryptionKey = DatasourceParameterType.GetEncryptionKey(Url.UserId);

            //Set the properties that are required for the datasource to work
            datasource.Url        = Url.Url;
            datasource.Parameters = new Dictionary <int, object>();
            foreach (DatasourceParameter dp in _parameters)
            {
                parameterType = null;

                //Find the correct type
                foreach (DatasourceParameterType currType in parameterTypes)
                {
                    if (currType.ParameterNumber == dp.ParameterNumber)
                    {
                        parameterType = currType;
                        break;
                    }
                }

                //Check if the parameter requires decryption
                if (parameterType != null && parameterType.Masked && dp.Value != null)
                {
                    parameterValue = SymmetricEncryption.DecryptData(encryptionKey, dp.Value.ToString());
                }
                else
                {
                    parameterValue = dp.Value;
                }

                datasource.Parameters.Add((int)dp.ParameterNumber, parameterValue);
            }
        }
 public void TDES()
 {
   SymmetricEncryption enc = new SymmetricEncryption(new TripleDESCryptoServiceProvider());
   for(int i = 1000; i < 1025; i ++) {
     byte[] data = new byte[1010];
     RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
     rng.GetBytes(data);
     byte[] encd = enc.EncryptData(data);
     if(i % 12 == 0) {
       continue;
     }
     byte[] decd = enc.DecryptData(encd);
     MemBlock mdecd = MemBlock.Reference(decd);
     MemBlock mdata = MemBlock.Reference(data);
     Assert.AreEqual(mdecd, mdata, "TDESEncryption: " + i);
   }
 }
        public void UploadFiles(Page page)
        {
            string filename = string.Empty; string lastItem = string.Empty;

            string[] arr = null; string[] separators = { "\\" }; string ID = string.Empty;



            HttpFileCollection fileCollection = basepage.Request.Files;

            //NetworkCredential NCredentials = new NetworkCredential(ShareLocationUserName, ShareLocationPassword, ShareLocationDomain);

            //using (new NetworkConnection(ShareFolderPath, NCredentials))

            ////using (new ImpersonatedUser(ShareLocationUserName, ShareLocationDomain, ShareLocationPassword))

            //{

            //  DriveMapping.DelDrive("i:", 0, true);
            //DriveMapping.MapDrive(@"\\10.138.74.233\c$\MaqasaAttachmentDocumentUpload", "Y:", @"agilityindia\tmurugesan", "mugil#2302");

            /// using (new NetworkConnection(@"\\server2\write", writeCredentials))

            ImpersonateUser     iU            = new ImpersonateUser();
            string              sPwd          = "";
            SymmetricEncryption CgServices    = ServiceFactory.GetSymmetricEncryptionInstance();;

            sPwd = CgServices.DecryptData(ConfigurationSettings.AppSettings["ShareLocationPassword"].ToString());
            iU.Impersonate(ConfigurationSettings.AppSettings["ShareLocationDomain"].ToString(), ConfigurationSettings.AppSettings["ShareLocationUserName"], sPwd);

            for (int i = 0; i < fileCollection.Count; i++)
            {
                HttpPostedFile uploadfile = fileCollection[i];

                if (uploadfile.ContentLength > 0)
                {
                    if (uploadfile.ContentLength >= FileUploadSizeInKB)
                    {
                        //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "message", "alert('you cannot upload files more than 1MB');", true);
                        //return;
                        filename = uploadfile.FileName;
                        arr      = filename.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                        lastItem = arr[arr.Length - 1];
                        if (Language == "ara")
                        {
                            lblMessage.Text = "أقصى حجم للملفات التي يمكن تحميلها هو 500 كيلوبايت. حجم الملف أكبر من 500 كيلوبايت." + " " + lastItem;
                        }
                        else
                        {
                            lblMessage.Text = lblMessage.Text + lastItem + " " + "Size is too large. Maximum file size of 500 KB is allowed." + " <br/>";
                        }
                        // return;
                    }
                    else
                    {
                        ID = GetNewID("MaqasaDocuments");
                        string fileName     = Path.GetFileName(uploadfile.FileName);
                        string GetFileName  = Path.GetFileNameWithoutExtension(uploadfile.FileName);
                        string GetExtension = Path.GetExtension(uploadfile.FileName);

                        string Date             = DateTime.Now.ToString("yyyy-MM-dd") + "\\" + ParentId;
                        string FullfileName     = GetFileName + ID + GetExtension;
                        string FullPathFileName = Date + "\\" + FullfileName;

                        ShareFolderPath = ShareFolderPath + "\\" + Date;
                        if (!Directory.Exists(ShareFolderPath))
                        {
                            Directory.CreateDirectory(ShareFolderPath);
                        }
                        string strpath = ShareFolderPath + "\\" + FullfileName;
                        uploadfile.SaveAs(strpath);


                        //byte[] buffer = new byte[uploadfile.ContentLength];
                        //uploadfile.InputStream.Read(buffer, 0, uploadfile.ContentLength);



                        //string contentType = uploadfile.ContentType;
                        //Stream FileStream = uploadfile.InputStream;
                        //BinaryReader br = new BinaryReader(FileStream);
                        //byte[] myData = br.ReadBytes((Int32)FileStream.Length);
                        //// byte[] myData = new byte[uploadfile.ContentLength];

                        string query = "insert into " + ProfileName + " (" + TablePrimaryKey + ",DocumentName,ReferenceId,NewFileName,StateId,Description,DateCreated,ReferenceType,MaqasaDocumentType) values (@DocumentId,@DocumentName, @ReferenceId, @NewFileName,@StateId,@Description,@DateCreated,@ReferenceType,@MaqasaDocumentType)";

                        SqlParameter[] commandParameters = new SqlParameter[9];
                        commandParameters[0] = new SqlParameter();
                        commandParameters[0].ParameterName = TablePrimaryKey;
                        commandParameters[0].Value         = ID;

                        commandParameters[1] = new SqlParameter();
                        commandParameters[1].ParameterName = "@DocumentName";
                        commandParameters[1].Value         = fileName;

                        commandParameters[2] = new SqlParameter();
                        commandParameters[2].ParameterName = "@ReferenceId";
                        commandParameters[2].Value         = ReferenceId;

                        commandParameters[3] = new SqlParameter();
                        commandParameters[3].ParameterName = "@NewFileName";
                        commandParameters[3].Value         = FullPathFileName;

                        commandParameters[4] = new SqlParameter();
                        commandParameters[4].ParameterName = "@StateId";
                        commandParameters[4].Value         = ProfileName + "CreatedState";

                        commandParameters[5] = new SqlParameter();
                        commandParameters[5].ParameterName = "@Description";
                        commandParameters[5].Value         = ((TextBox)page.FindControl("txtDescription")).Text;

                        commandParameters[6] = new SqlParameter();
                        commandParameters[6].ParameterName = "@DateCreated";
                        commandParameters[6].Value         = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");

                        commandParameters[7] = new SqlParameter();
                        commandParameters[7].ParameterName = "@ReferenceType";
                        commandParameters[7].Value         = ReferenceType;

                        commandParameters[8] = new SqlParameter();
                        commandParameters[8].ParameterName = "@MaqasaDocumentType";
                        commandParameters[8].Value         = Convert.ToInt32(ddlDocumentTypes.SelectedValue);

                        SQLDataAccessHelper.Instance.ExecuteNonQuery(CommandType.Text, query, commandParameters);

                        //string constr = ConfigurationManager.ConnectionStrings["SQLConnectionString"].ConnectionString;
                        //using (SqlConnection con = new SqlConnection(constr))
                        //{
                        //    //Commented by subramanyam for adding MaqasaDocumentType column
                        //    //string query = "insert into " + ProfileName + " (" + TablePrimaryKey + ",DocumentName,ReferenceId,NewFileName,StateId,Description,DateCreated,ReferenceType) values (@DocumentId,@DocumentName, @ReferenceId, @NewFileName,@StateId,@Description,@DateCreated,@ReferenceType)";
                        //string query = "insert into " + ProfileName + " (" + TablePrimaryKey + ",DocumentName,ReferenceId,NewFileName,StateId,Description,DateCreated,ReferenceType,MaqasaDocumentType) values (@DocumentId,@DocumentName, @ReferenceId, @NewFileName,@StateId,@Description,@DateCreated,@ReferenceType,@MaqasaDocumentType)";
                        //using (SqlCommand cmd = new SqlCommand(query))
                        //{
                        //    cmd.Connection = con;
                        //    cmd.Parameters.AddWithValue(TablePrimaryKey, ID);
                        //    cmd.Parameters.AddWithValue("@DocumentName", fileName);
                        //    cmd.Parameters.AddWithValue("@ReferenceId", ReferenceId);
                        //    cmd.Parameters.AddWithValue("@NewFileName", FullPathFileName);
                        //    cmd.Parameters.AddWithValue("@StateId", ProfileName + "CreatedState");
                        //    cmd.Parameters.AddWithValue("@Description", ((TextBox)page.FindControl("txtDescription")).Text);
                        //    cmd.Parameters.AddWithValue("@DateCreated", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff"));
                        //    cmd.Parameters.AddWithValue("@ReferenceType", ReferenceType);
                        //    //Added by subramanyam
                        //    cmd.Parameters.AddWithValue("@MaqasaDocumentType", Convert.ToInt32(ddlDocumentTypes.SelectedValue));
                        //    con.Open();
                        //    cmd.ExecuteNonQuery();
                        //    con.Close();
                        //}
                        //}
                    }
                }
                else
                {
                    filename = uploadfile.FileName;
                    arr      = filename.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                    lastItem = arr[arr.Length - 1];
                    if (Language == "ara")
                    {
                        lblMessage.Text = lblMessage.Text + lastItem + " " + "الملف فارغ" + " <br/>";
                    }
                    else
                    {
                        lblMessage.Text = lblMessage.Text + lastItem + " " + "file is empty" + " <br/>";
                    }
                    //return;
                    //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "message", "alert('you did not specify a file to upload?');", true);
                    //return;
                }
            }

            iU.Undo();

            //}
            TextBox stxtDescription = ((TextBox)page.FindControl("txtDescription"));

            stxtDescription.Text           = "";
            ddlDocumentTypes.SelectedIndex = 0;
            BindGrid(GridView1);
        }
        public void DownloadFiles(Page page, object sender)
        {
            try
            {
                byte[] bytes; string NewFileName = string.Empty;
                string fileName = string.Empty; string strpath = string.Empty;
                int    id = int.Parse((sender as LinkButton).CommandArgument);

                string         CommandText       = "select " + TablePrimaryKey + ",DocumentName, NewFileName from  " + ProfileName + "  where " + TablePrimaryKey + " =@Id";
                SqlParameter[] commandParameters = new SqlParameter[1];
                commandParameters[0] = new SqlParameter();
                commandParameters[0].ParameterName = "@Id";
                commandParameters[0].Value         = id;

                using (SqlDataReader sdr = SQLDataAccessHelper.Instance.ExecuteReader(CommandType.Text, CommandText, commandParameters))
                {
                    sdr.Read();
                    NewFileName = sdr["NewFileName"].ToString();
                    fileName    = sdr["DocumentName"].ToString();

                    ImpersonateUser     iU         = new ImpersonateUser();
                    string              sPwd       = "";
                    SymmetricEncryption CgServices = ServiceFactory.GetSymmetricEncryptionInstance();;
                    sPwd = CgServices.DecryptData(ConfigurationSettings.AppSettings["ShareLocationPassword"].ToString());
                    iU.Impersonate(ConfigurationSettings.AppSettings["ShareLocationDomain"].ToString(), ConfigurationSettings.AppSettings["ShareLocationUserName"], sPwd);

                    strpath = Path.Combine(ShareFolderPath, NewFileName);;
                    System.IO.FileStream fs = null;
                    fs    = System.IO.File.Open(strpath, System.IO.FileMode.Open);
                    bytes = new byte[fs.Length];
                    fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
                    fs.Close();
                    //}

                    iU.Undo();
                }

                //string constr = ConfigurationManager.ConnectionStrings["SQLConnectionString"].ConnectionString;
                //using (SqlConnection con = new SqlConnection(constr))
                //{
                //    using (SqlCommand cmd = new SqlCommand())
                //    {
                //        cmd.CommandText = "select " + TablePrimaryKey + ",DocumentName, NewFileName from  " + ProfileName + "  where " + TablePrimaryKey + " =@Id";
                //        cmd.Parameters.AddWithValue("@Id", id);
                //        cmd.Connection = con;
                //        con.Open();
                //        using (SqlDataReader sdr = cmd.ExecuteReader())
                //        {
                //            sdr.Read();
                //            NewFileName = sdr["NewFileName"].ToString();
                //            fileName = sdr["DocumentName"].ToString();

                //            //NetworkCredential NCredentials = new NetworkCredential(ShareLocationUserName, ShareLocationPassword, ShareLocationDomain);

                //            //using (new NetworkConnection(ShareFolderPath, NCredentials))
                //            //{

                //            ImpersonateUser iU = new ImpersonateUser();
                //            string sPwd = "";
                //            SymmetricEncryption CgServices = ServiceFactory.GetSymmetricEncryptionInstance(); ;
                //            sPwd = CgServices.DecryptData(ConfigurationSettings.AppSettings["ShareLocationPassword"].ToString());
                //            iU.Impersonate(ConfigurationSettings.AppSettings["ShareLocationDomain"].ToString(), ConfigurationSettings.AppSettings["ShareLocationUserName"], sPwd);

                //            strpath = Path.Combine(ShareFolderPath, NewFileName); ;
                //            System.IO.FileStream fs = null;
                //            fs = System.IO.File.Open(strpath, System.IO.FileMode.Open);
                //            bytes = new byte[fs.Length];
                //            fs.Read(bytes, 0, Convert.ToInt32(fs.Length));
                //            fs.Close();
                //            //}

                //            iU.Undo();
                //        }
                //    }
                //    con.Close();

                //}

                page.Response.Clear();
                page.Response.Buffer      = true;
                page.Response.ContentType = "application/octet-stream";
                page.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
                page.Response.Charset = "";
                //Response.Cache.SetCacheability(HttpCacheability.NoCache);
                if (bytes.Length > 0)
                {
                    page.Response.OutputStream.Write(bytes, 0, (int)bytes.Length);
                }

                page.Response.Flush();
                //bytes=new Byte[test];
                page.Response.End();
            }

            catch (Exception ex)
            {
                ex.Message.ToString();
            }
        }
 ///<summary>Decrypts the packet given a SymmetricEncryption returning true
 ///if it was able to decrypt it.</summary>
 public bool Decrypt(SymmetricEncryption se) {
   byte[] decrypted = se.DecryptData(_encrypted_data);
   int pos = 0;
   int data_len = NumberSerializer.ReadInt(decrypted, pos);
   pos += 4;
   _data = MemBlock.Reference(decrypted, pos, data_len);
   pos += data_len;
   _signature = MemBlock.Reference(decrypted, pos, decrypted.Length - pos);
   return true;
 }