Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="token"></param>
        /// <param name="expectedLength"></param>
        /// <returns></returns>
        public string[] Decode(string token, int expectedLength)
        {
            if (token.IsEmpty())
            {
                throw new ArgumentNullException("token");
            }

            var d = CipherUtil.Decrypt <AesManaged>(token, this.password, this.salt);

            if (d.IsEmpty())
            {
                throw new ArgumentException("Token is empty");
            }

            var r = d.Split(this.SplitToken);

            if (this.ExpirationSeconds > 0)
            {
                expectedLength++;
            }

            if (expectedLength > 0 && (r == null || r.Length != expectedLength))
            {
                throw new ArgumentException(String.Format("Invalid Token Length.  Expected: {0} - Received: {1}", expectedLength, (r == null ? "Nothing" : r.Length.ToString())));
            }

            return(this.CheckExpiration(r));
        }
Beispiel #2
0
 public void LoadBackupSettings()
 {
     if (File.Exists(Helper.AppConstants.UiConfigSavedPath +
                     Helper.AppConstants.BackupConfigFileName))
     {
         var EncryptedXml = File.ReadAllText(Helper.AppConstants.UiConfigSavedPath +
                                             Helper.AppConstants.BackupConfigFileName);
         var DecryptedXml  = CipherUtil.Decrypt(EncryptedXml, Helper.AppConstants.CipherKey);
         var ObjBackConfig = Helper.XmlStringToObject <BackupConfig>(DecryptedXml);
         SetBackupConfig(ObjBackConfig);
     }
 }
Beispiel #3
0
        void LoadDataGridWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            ImageVisibility(true);
            ProcessingStatus("Loading backup logs...");

            try
            {
                var logPath      = Helper.GetLogPathForUi;
                var CurrentMonth = DateTime.Now.ToString("MMMM");
                logPath = logPath + "\\" + e.Argument.ToString();
                List <string> files = new List <string>();
                if (Directory.Exists(logPath))
                {
                    files = Directory.GetFiles(logPath).ToList();
                    files.OrderByDescending(m => Name);
                }
                List <BackupSuccessLog> objListBackupSuccessLog = new List <BackupSuccessLog>();

                foreach (var item in files)
                {
                    var EncryptedXml        = File.ReadAllText(item);
                    var DecryptedXml        = CipherUtil.Decrypt(EncryptedXml, Helper.AppConstants.CipherKey);
                    var ObjBackupSuccessLog = Helper.XmlStringToObject <BackupSuccessLog>(DecryptedXml);
                    objListBackupSuccessLog.Add(ObjBackupSuccessLog);
                }

                List <DataTableBackupSuccessLog> objDtLogs = new List <DataTableBackupSuccessLog>();
                foreach (var item in objListBackupSuccessLog)
                {
                    for (var i = 0; i < item.DatabaseName.Count; i++)
                    {
                        DataTableBackupSuccessLog obj = new DataTableBackupSuccessLog();
                        obj.DatabaseName = item.DatabaseName[i];
                        obj.DateTime     = item.DateTime[i];
                        obj.BackupType   = item.BackupType[i];
                        obj.Status       = item.Status[i];
                        obj.Location     = item.Location[i];
                        objDtLogs.Add(obj);
                    }
                }

                var dt = Helper.ToDataTable <DataTableBackupSuccessLog>(objDtLogs);
                e.Result = dt;
                ImageVisibility(false);
            }
            catch (Exception ex)
            {
                ImageVisibility(false);
                log.Error(ex);
            }
            idLabelLogMonth.Text = idCmbSelectMonth.Text + " Logs";
        }
Beispiel #4
0
        private AccessToken CreateAccessToken()
        {
            var secret = CipherUtil.Decrypt <AesManaged>(Settings.GIF_ENCRYPTED_CLIENT_SECRET(_config), "GifService", Settings.GIF_AZURE_CLIENT_ID(_config));

            var result = _authContext
                         .AcquireTokenAsync(Settings.GIF_CRM_URL(_config), new ClientCredential(Settings.GIF_AZURE_CLIENT_ID(_config), secret))
                         .Result;

            var accessToken = new AccessToken
            {
                expires_on   = result.ExpiresOn,
                access_token = result.AccessToken
            };

            return(accessToken);
        }
Beispiel #5
0
        // GET: Administracion/Usuarios/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Usuarios usuarios = db.Usuarios.Find(id);

            usuarios.password_hash = CipherUtil.Decrypt(usuarios.password_hash);

            if (usuarios == null)
            {
                return(HttpNotFound());
            }

            ViewBag.id_aplicacion = new SelectList(db.Aplicaciones, "id_aplicacion", "nombre");
            return(View(usuarios));
        }
Beispiel #6
0
        public void LoadDataGrid()
        {
            try
            {
                var logPath      = Helper.GetLogPathForUi;
                var CurrentMonth = DateTime.Now.ToString("MMMM");
                logPath = logPath + "\\" + idCmbSelectMonth.Text;
                var files = Directory.GetFiles(logPath);
                files.OrderByDescending(m => Name);
                List <BackupSuccessLog> objListBackupSuccessLog = new List <BackupSuccessLog>();

                foreach (var item in files)
                {
                    var EncryptedXml        = File.ReadAllText(item);
                    var DecryptedXml        = CipherUtil.Decrypt(EncryptedXml, Helper.AppConstants.CipherKey);
                    var ObjBackupSuccessLog = Helper.XmlStringToObject <BackupSuccessLog>(DecryptedXml);
                    objListBackupSuccessLog.Add(ObjBackupSuccessLog);
                }

                List <DataTableBackupSuccessLog> objDtLogs = new List <DataTableBackupSuccessLog>();
                foreach (var item in objListBackupSuccessLog)
                {
                    for (var i = 0; i < item.DatabaseName.Count; i++)
                    {
                        DataTableBackupSuccessLog obj = new DataTableBackupSuccessLog();
                        obj.DatabaseName = item.DatabaseName[i];
                        obj.DateTime     = item.DateTime[i];
                        obj.BackupType   = item.BackupType[i];
                        obj.Status       = item.Status[i];
                        obj.Location     = item.Location[i];
                        objDtLogs.Add(obj);
                    }
                }
                var dt = Helper.ToDataTable <DataTableBackupSuccessLog>(objDtLogs);
                idDataGridViewBackupLog.DataSource = dt;
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }
Beispiel #7
0
 void SendZipPasswordWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         ImageVisibility(true);
         ProcessingStatus("Sending Zip password to registered mail...");
         var MailConfigPath    = System.AppDomain.CurrentDomain.BaseDirectory + "\\App_Data\\" + Helper.AppConstants.MailConfigFileName;
         var EncryptedXml      = File.ReadAllText(MailConfigPath);
         var DecryptedXml      = CipherUtil.Decrypt(EncryptedXml, Helper.AppConstants.CipherKey);
         var ObjMailSettings   = Helper.XmlStringToObject <MailConfig>(DecryptedXml);
         var ObjBackupSettings = Helper.GetBackupConfig();
         Mailer.SendZipPassword(ObjMailSettings, ObjBackupSettings.BackupPassword);
         ImageVisibility(false);
         MessageBox.Show("Zip password sent to mail successfully.");
     }
     catch (Exception ex)
     {
         e.Cancel = true;
         ImageVisibility(false);
         log.Error(ex);
     }
 }
Beispiel #8
0
        public static BackupConfig GetBackConfig()
        {
            var BackupConfigPath = Helper.GetBackupConfigPathForService;

            if (File.Exists(BackupConfigPath))
            {
                if (File.Exists(BackupConfigPath))
                {
                    var EncryptedXml  = File.ReadAllText(BackupConfigPath);
                    var DecryptedXml  = CipherUtil.Decrypt(EncryptedXml, Helper.AppConstants.CipherKey);
                    var ObjBackConfig = Helper.XmlStringToObject <BackupConfig>(DecryptedXml);
                    return(ObjBackConfig);
                }
                else
                {
                    return(new BackupConfig());
                }
            }
            else
            {
                log.Error("Backup config file does not exist or corrupted.");
                return(new BackupConfig());
            }
        }
        public void Decrypt()
        {
            var value = CipherUtil.Decrypt <AesManaged>(ENCRYPT_VALUE, PASSWORD, SALT);

            Assert.Equal(value, TEST_VALUE);
        }