Beispiel #1
0
        public UsuarioTO IsValid(string usuario, string password, string empresaDS, string ipAdd)
        {
            string      password_hash_local = CipherUtil.Encrypt(password);
            AppEntities db = new AppEntities(empresaDS);

            //inicializando el objeto que devolvera el usuario en base de datos;
            UsuarioTO usuarioTO = new UsuarioTO();

            usuarioTO.EmpresaDS = empresaDS;
            usuarioTO.IPAddress = ipAdd;
            usuarioTO.Valid     = false;

            var usuarioMatch = db.Usuarios.Where(
                u => u.usuario == usuario &&
                u.password_hash == password_hash_local &&
                !u.bloqueo_habilitado &&
                !u.eliminado
                ).DefaultIfEmpty(null).Single();

            if (usuarioMatch != null)
            {
                usuarioTO.Valid   = true;
                usuarioTO.usuario = usuarioMatch;

                //populando roles por usuario
                foreach (Roles rol in usuarioMatch.Roles)
                {
                    foreach (Rol_Acciones rolAcciones in rol.Rol_Acciones)
                    {
                        usuarioTO.fillPermisions(rol.Aplicaciones.ruta, rolAcciones.Controladores.nombre, rolAcciones.Acciones.nombre);
                    }
                }
            }
            return(usuarioTO);
        }
Beispiel #2
0
        public void BlockDecrypt(byte[] input, int inOffset, byte[] output, int outOffset)
        {
            uint t;
            int  i;

            uint[] lr = new uint[2];

            lr[0] = CipherUtil.GetIntLE(input, inOffset);
            lr[1] = CipherUtil.GetIntLE(input, inOffset + 4);

            initPerm(lr);

            t     = (lr[1] << 1) | (lr[1] >> 31);
            lr[1] = (lr[0] << 1) | (lr[0] >> 31);
            lr[0] = t;

            for (i = 30; i > 0; i -= 4)
            {
                desCipher1(lr, i);
                desCipher2(lr, i - 2);
            }

            lr[0] = (lr[0] >> 1) | (lr[0] << 31);
            lr[1] = (lr[1] >> 1) | (lr[1] << 31);

            finalPerm(lr);

            CipherUtil.PutIntLE(lr[0], output, outOffset);
            CipherUtil.PutIntLE(lr[1], output, outOffset + 4);
        }
Beispiel #3
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 #4
0
        public void InitializeKey(byte[] key, int offset)
        {
            uint i, c, d, t, s, shifts;

            c = CipherUtil.GetIntLE(key, offset + 0);
            d = CipherUtil.GetIntLE(key, offset + 4);

            t  = ((d >> 4) ^ c) & 0x0f0f0f0f;
            c ^= t;
            d ^= t << 4;
            t  = (((c << (16 - (-2))) ^ c) & 0xcccc0000);
            c  = c ^ t ^ (t >> (16 - (-2)));
            t  = (((d << (16 - (-2))) ^ d) & 0xcccc0000);
            d  = d ^ t ^ (t >> (16 - (-2)));
            t  = ((d >> 1) ^ c) & 0x55555555;
            c ^= t;
            d ^= t << 1;
            t  = ((c >> 8) ^ d) & 0x00ff00ff;
            d ^= t;
            c ^= t << 8;
            t  = ((d >> 1) ^ c) & 0x55555555;
            c ^= t;
            d ^= t << 1;

            d = ((d & 0xff) << 16) | (d & 0xff00) |
                ((d >> 16) & 0xff) | ((c >> 4) & 0xf000000);
            c     &= 0x0fffffff;
            shifts = 0x7efc;

            for (i = 0; i < 16; i++)
            {
                if ((shifts & 1) != 0)
                {
                    c = ((c >> 2) | (c << 26));
                    d = ((d >> 2) | (d << 26));
                }
                else
                {
                    c = ((c >> 1) | (c << 27));
                    d = ((d >> 1) | (d << 27));
                }
                shifts >>= 1;
                c       &= 0x0fffffff;
                d       &= 0x0fffffff;

                s = SKB[0, (c) & 0x3f] |
                    SKB[1, ((c >> 6) & 0x03) | ((c >> 7) & 0x3c)] |
                    SKB[2, ((c >> 13) & 0x0f) | ((c >> 14) & 0x30)] |
                    SKB[3, ((c >> 20) & 0x01) | ((c >> 21) & 0x06) | ((c >> 22) & 0x38)];

                t = SKB[4, (d) & 0x3f] |
                    SKB[5, ((d >> 7) & 0x03) | ((d >> 8) & 0x3c)] |
                    SKB[6, (d >> 15) & 0x3f] |
                    SKB[7, ((d >> 21) & 0x0f) | ((d >> 22) & 0x30)];

                _key[i * 2]       = ((t << 16) | (s & 0xffff));
                s                 = ((s >> 16) | (t & 0xffff0000));
                _key[(i * 2) + 1] = (s << 4) | (s >> 28);
            }
        }
Beispiel #5
0
        public void initializeKey(byte[] key)
        {
            int  i, j, len = key.Length;
            uint temp;

            Array.Copy(blowfish_pbox, 0, P, 0, 18);
            Array.Copy(blowfish_sbox, 0, S0, 0, 256);
            Array.Copy(blowfish_sbox, 256, S1, 0, 256);
            Array.Copy(blowfish_sbox, 512, S2, 0, 256);
            Array.Copy(blowfish_sbox, 768, S3, 0, 256);

            for (j = 0, i = 0; i < 16 + 2; i++)
            {
                temp = (((uint)(key[j]) << 24) |
                        ((uint)(key[(j + 1) % len]) << 16) |
                        ((uint)(key[(j + 2) % len]) << 8) |
                        ((uint)(key[(j + 3) % len])));
                P[i] = P[i] ^ temp;
                j    = (j + 4) % len;
            }

            byte[] LR = new byte[8];

            for (i = 0; i < 16 + 2; i += 2)
            {
                blockEncrypt(LR, 0, LR, 0);
                P[i]     = CipherUtil.GetIntBE(LR, 0);
                P[i + 1] = CipherUtil.GetIntBE(LR, 4);
            }

            for (j = 0; j < 256; j += 2)
            {
                blockEncrypt(LR, 0, LR, 0);
                S0[j]     = CipherUtil.GetIntBE(LR, 0);
                S0[j + 1] = CipherUtil.GetIntBE(LR, 4);
            }
            for (j = 0; j < 256; j += 2)
            {
                blockEncrypt(LR, 0, LR, 0);
                S1[j]     = CipherUtil.GetIntBE(LR, 0);
                S1[j + 1] = CipherUtil.GetIntBE(LR, 4);
            }
            for (j = 0; j < 256; j += 2)
            {
                blockEncrypt(LR, 0, LR, 0);
                S2[j]     = CipherUtil.GetIntBE(LR, 0);
                S2[j + 1] = CipherUtil.GetIntBE(LR, 4);
            }
            for (j = 0; j < 256; j += 2)
            {
                blockEncrypt(LR, 0, LR, 0);
                S3[j]     = CipherUtil.GetIntBE(LR, 0);
                S3[j + 1] = CipherUtil.GetIntBE(LR, 4);
            }
        }
Beispiel #6
0
 public ActionResult Edit([Bind(Include = "id_usuario,email,password_hash,bloqueo_habilitado,usuario,nombre_completo_usuario,usuario_externo")] Usuarios usuarios)
 {
     if (ModelState.IsValid)
     {
         usuarios.password_hash   = CipherUtil.Encrypt(usuarios.password_hash);
         db.Entry(usuarios).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(usuarios));
 }
Beispiel #7
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 #8
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 #9
0
        public void encryptCBC(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)
        {
            int nBlocks = inputLen / BLOCK_SIZE;

            for (int bc = 0; bc < nBlocks; bc++)
            {
                CipherUtil.BlockXor(input, inputOffset, BLOCK_SIZE, IV, 0);
                blockEncrypt(IV, 0, output, outputOffset);
                Array.Copy(output, outputOffset, IV, 0, BLOCK_SIZE);
                inputOffset  += BLOCK_SIZE;
                outputOffset += BLOCK_SIZE;
            }
        }
Beispiel #10
0
        public void EncryptCBC(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)
        {
            int nBlocks = inputLen / 8;

            for (int bc = 0; bc < nBlocks; bc++)
            {
                CipherUtil.BlockXor(input, inputOffset, 8, _iv, 0);
                BlockEncrypt(_iv, 0, output, outputOffset);
                Array.Copy(output, outputOffset, _iv, 0, 8);
                inputOffset  += 8;
                outputOffset += 8;
            }
        }
Beispiel #11
0
        public void encryptCBC(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)
        {
            int block_size = GetBlockSize();
            int nBlocks    = inputLen / block_size;

            for (int bc = 0; bc < nBlocks; bc++)
            {
                CipherUtil.BlockXor(input, inputOffset, block_size, _IV, 0);
                blockEncrypt(_IV, 0, output, outputOffset);
                Array.Copy(output, outputOffset, _IV, 0, block_size);
                inputOffset  += block_size;
                outputOffset += block_size;
            }
        }
Beispiel #12
0
        public ActionResult Create([Bind(Include = "email,password_hash,usuario,nombre_completo_usuario,telefono_trabajo,telefono_movil,usuario_externo")] Usuarios usuarios)
        {
            if (ModelState.IsValid)
            {
                usuarios.password_hash           = CipherUtil.Encrypt(usuarios.password_hash);
                usuarios.conteo_accesos_fallidos = 0;
                usuarios.bloqueo_habilitado      = false;
                db.Usuarios.Add(usuarios);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(usuarios));
        }
Beispiel #13
0
        internal void ExpandState(byte[] key)
        {
            int keyLen = key.Length;

            for (int j = 0, i = 0; i < 16 + 2; i++)
            {
                uint temp =
                    (((uint)(key[j]) << 24) |
                     ((uint)(key[(j + 1) % keyLen]) << 16) |
                     ((uint)(key[(j + 2) % keyLen]) << 8) |
                     ((uint)(key[(j + 3) % keyLen])));
                P[i] = P[i] ^ temp;
                j    = (j + 4) % keyLen;
            }

            byte[] LR = new byte[8];

            for (int i = 0; i < 16 + 2; i += 2)
            {
                BlockEncrypt(LR, 0, LR, 0);
                P[i]     = CipherUtil.GetIntBE(LR, 0);
                P[i + 1] = CipherUtil.GetIntBE(LR, 4);
            }

            for (int j = 0; j < 256; j += 2)
            {
                BlockEncrypt(LR, 0, LR, 0);
                S0[j]     = CipherUtil.GetIntBE(LR, 0);
                S0[j + 1] = CipherUtil.GetIntBE(LR, 4);
            }
            for (int j = 0; j < 256; j += 2)
            {
                BlockEncrypt(LR, 0, LR, 0);
                S1[j]     = CipherUtil.GetIntBE(LR, 0);
                S1[j + 1] = CipherUtil.GetIntBE(LR, 4);
            }
            for (int j = 0; j < 256; j += 2)
            {
                BlockEncrypt(LR, 0, LR, 0);
                S2[j]     = CipherUtil.GetIntBE(LR, 0);
                S2[j + 1] = CipherUtil.GetIntBE(LR, 4);
            }
            for (int j = 0; j < 256; j += 2)
            {
                BlockEncrypt(LR, 0, LR, 0);
                S3[j]     = CipherUtil.GetIntBE(LR, 0);
                S3[j + 1] = CipherUtil.GetIntBE(LR, 4);
            }
        }
Beispiel #14
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 #15
0
        public void encryptCTR(byte[] input, int inputOffset, int inputLen, byte[] output, int outputOffset)
        {
            int block_size = GetBlockSize();
            int nBlocks    = inputLen / block_size;

            byte[] tmpBlk = new byte[block_size];
            for (int bc = 0; bc < nBlocks; bc++)
            {
                blockEncrypt(_IV, 0, tmpBlk, 0);
                CipherUtil.BlockXor(input, inputOffset, block_size, tmpBlk, 0);
                Array.Copy(tmpBlk, 0, output, outputOffset, block_size);
                incrementIV();
                inputOffset  += block_size;
                outputOffset += block_size;
            }
        }
Beispiel #16
0
        public UsuarioTO IsValid(string usuario, string password, string empresaDS, string ipAdd, int usuario_loguea)
        {
            string      password_hash_local = CipherUtil.Encrypt(password);
            AppEntities db = new AppEntities(empresaDS);

            //inicializando el objeto que devolvera el usuario en base de datos;
            UsuarioTO usuarioTO = new UsuarioTO();

            usuarioTO.EmpresaDS = empresaDS;
            usuarioTO.IPAddress = ipAdd;
            usuarioTO.Valid     = false;

            List <string> usuariosAutorizados = new List <string>
            {
                "admin", "admin.geo"
            };

            if (usuariosAutorizados.Contains(usuario))
            {
                Usuarios usuarioMatch = db.Usuarios.Where(u =>
                                                          u.usuario == usuario &&
                                                          u.password_hash == password_hash_local &&
                                                          u.bloqueo_habilitado == false
                                                          ).DefaultIfEmpty(null).SingleOrDefault();

                Usuarios usuarioALoggear = db.Usuarios.Where(u =>
                                                             u.id_usuario == usuario_loguea &&
                                                             u.bloqueo_habilitado == false
                                                             ).DefaultIfEmpty(null).SingleOrDefault();

                if (usuarioMatch != null && usuarioALoggear != null)
                {
                    usuarioTO.Valid   = true;
                    usuarioTO.usuario = usuarioALoggear;

                    //populando roles por usuario
                    foreach (Roles rol in usuarioALoggear.Roles)
                    {
                        foreach (Rol_Acciones rolAcciones in rol.Rol_Acciones)
                        {
                            usuarioTO.fillPermisions(rol.Aplicaciones.ruta, rolAcciones.Controladores.nombre, rolAcciones.Acciones.nombre);
                        }
                    }
                }
            }
            return(usuarioTO);
        }
Beispiel #17
0
        public void blockDecrypt(byte[] input, int inOffset, byte[] output, int outOffset)
        {
            uint L, R;

            L = CipherUtil.GetIntBE(input, inOffset);
            R = CipherUtil.GetIntBE(input, inOffset + 4);

            L ^= P[17];
            R ^= ((((S0[(int)((L >> 24) & 0xff)] + S1[(int)((L >> 16) & 0xff)]) ^
                    S2[(int)((L >> 8) & 0xff)]) + S3[(int)(L & 0xff)]) ^ P[16]);
            L ^= ((((S0[(int)((R >> 24) & 0xff)] + S1[(int)((R >> 16) & 0xff)]) ^
                    S2[(int)((R >> 8) & 0xff)]) + S3[(int)(R & 0xff)]) ^ P[15]);
            R ^= ((((S0[(int)((L >> 24) & 0xff)] + S1[(int)((L >> 16) & 0xff)]) ^
                    S2[(int)((L >> 8) & 0xff)]) + S3[(int)(L & 0xff)]) ^ P[14]);
            L ^= ((((S0[(int)((R >> 24) & 0xff)] + S1[(int)((R >> 16) & 0xff)]) ^
                    S2[(int)((R >> 8) & 0xff)]) + S3[(int)(R & 0xff)]) ^ P[13]);
            R ^= ((((S0[(int)((L >> 24) & 0xff)] + S1[(int)((L >> 16) & 0xff)]) ^
                    S2[(int)((L >> 8) & 0xff)]) + S3[(int)(L & 0xff)]) ^ P[12]);
            L ^= ((((S0[(int)((R >> 24) & 0xff)] + S1[(int)((R >> 16) & 0xff)]) ^
                    S2[(int)((R >> 8) & 0xff)]) + S3[(int)(R & 0xff)]) ^ P[11]);
            R ^= ((((S0[(int)((L >> 24) & 0xff)] + S1[(int)((L >> 16) & 0xff)]) ^
                    S2[(int)((L >> 8) & 0xff)]) + S3[(int)(L & 0xff)]) ^ P[10]);
            L ^= ((((S0[(int)((R >> 24) & 0xff)] + S1[(int)((R >> 16) & 0xff)]) ^
                    S2[(int)((R >> 8) & 0xff)]) + S3[(int)(R & 0xff)]) ^ P[9]);
            R ^= ((((S0[(int)((L >> 24) & 0xff)] + S1[(int)((L >> 16) & 0xff)]) ^
                    S2[(int)((L >> 8) & 0xff)]) + S3[(int)(L & 0xff)]) ^ P[8]);
            L ^= ((((S0[(int)((R >> 24) & 0xff)] + S1[(int)((R >> 16) & 0xff)]) ^
                    S2[(int)((R >> 8) & 0xff)]) + S3[(int)(R & 0xff)]) ^ P[7]);
            R ^= ((((S0[(int)((L >> 24) & 0xff)] + S1[(int)((L >> 16) & 0xff)]) ^
                    S2[(int)((L >> 8) & 0xff)]) + S3[(int)(L & 0xff)]) ^ P[6]);
            L ^= ((((S0[(int)((R >> 24) & 0xff)] + S1[(int)((R >> 16) & 0xff)]) ^
                    S2[(int)((R >> 8) & 0xff)]) + S3[(int)(R & 0xff)]) ^ P[5]);
            R ^= ((((S0[(int)((L >> 24) & 0xff)] + S1[(int)((L >> 16) & 0xff)]) ^
                    S2[(int)((L >> 8) & 0xff)]) + S3[(int)(L & 0xff)]) ^ P[4]);
            L ^= ((((S0[(int)((R >> 24) & 0xff)] + S1[(int)((R >> 16) & 0xff)]) ^
                    S2[(int)((R >> 8) & 0xff)]) + S3[(int)(R & 0xff)]) ^ P[3]);
            R ^= ((((S0[(int)((L >> 24) & 0xff)] + S1[(int)((L >> 16) & 0xff)]) ^
                    S2[(int)((L >> 8) & 0xff)]) + S3[(int)(L & 0xff)]) ^ P[2]);
            L ^= ((((S0[(int)((R >> 24) & 0xff)] + S1[(int)((R >> 16) & 0xff)]) ^
                    S2[(int)((R >> 8) & 0xff)]) + S3[(int)(R & 0xff)]) ^ P[1]);
            R ^= P[0];

            CipherUtil.PutIntBE(R, output, outOffset);
            CipherUtil.PutIntBE(L, output, outOffset + 4);
        }
Beispiel #18
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 #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="values"></param>
        /// <returns></returns>
        public string Create(params string[] values)
        {
            if (values == null || values.Length == 0)
            {
                throw new ArgumentNullException("values");
            }

            var list = new List <string>(values);

            if (this.ExpirationSeconds > 0)
            {
                list.Insert(0, DateTime.UtcNow.AddSeconds(this.ExpirationSeconds).ToString());
            }

            var r = String.Join(this.SplitToken.ToString(), list.ToArray());

            return(CipherUtil.Encrypt <AesManaged>(r, this.password, this.salt));
        }
Beispiel #20
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 #21
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 #22
0
        private void idBtnSaveSettings_Click(object sender, EventArgs e)
        {
            try
            {
                var Isvalid = ValidateMailForm();

                if (Isvalid == false)
                {
                    return;
                }

                if (!IsEmailValid(idTxtMailFrom.Text.Trim()))
                {
                    MessageBox.Show("Please enter a valid email address [Mail From]");
                    return;
                }

                ImageVisibility(true);
                ProcessingStatus("Saving Settings...");
                var objMailConfig = GetMailSettings();

                var XmlString = Helper.ToXml(objMailConfig);

                var EncryptedXml = CipherUtil.Encrypt(XmlString, Helper.AppConstants.CipherKey);
                if (!Directory.Exists(Helper.AppConstants.UiConfigSavedPath))
                {
                    Directory.CreateDirectory(Helper.AppConstants.UiConfigSavedPath);
                }
                File.WriteAllText(Helper.AppConstants.UiConfigSavedPath + Helper.AppConstants.MailConfigFileName, EncryptedXml);
                log.Info("New Mail settings saved");
                ImageVisibility(false);
                MessageBox.Show("Mail Settings saved");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                log.Error(ex.Message);
            }
        }
Beispiel #23
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);
        }
Beispiel #25
0
        void SaveBackupSettings_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            ImageVisibility(true);
            ProcessingStatus("Saving Settings...");
            if (e.Result is Exception)
            {
                return;
            }
            bool IsValid = true;

            try
            {
                IsValid = ValidateServerCredentials();
                if (IsValid == false)
                {
                    ImageVisibility(false);
                    return;
                }
                IsValid = ValidateBackupDirectory();
                if (IsValid == false)
                {
                    ImageVisibility(false);
                    return;
                }
                IsValid = IsValidInputDatabase();
                if (IsValid == false)
                {
                    ImageVisibility(false);
                    return;
                }
                IsValid = ValidateBackupPassword();
                if (IsValid == false)
                {
                    ImageVisibility(false);
                    return;
                }

                if (!Directory.Exists(idTxtBackupLocation.Text))
                {
                    MessageBox.Show("Backup directory not found.");
                    ImageVisibility(false);
                    return;
                }

                var objBackConfig = GetBackupConfig();
                var XmlString     = Helper.ToXml(objBackConfig);

                var EncryptedXml = CipherUtil.Encrypt(XmlString, Helper.AppConstants.CipherKey);
                if (!Directory.Exists(Helper.AppConstants.UiConfigSavedPath))
                {
                    Directory.CreateDirectory(Helper.AppConstants.UiConfigSavedPath);
                }
                File.WriteAllText(Helper.AppConstants.UiConfigSavedPath + Helper.AppConstants.BackupConfigFileName, EncryptedXml);
                log.Info("New backup settings saved");
                try
                {
                    var ServiceList = ServiceController.GetServices();
                    foreach (ServiceController service in ServiceList)
                    {
                        if (service.ServiceName.Contains(Helper.ApplicationInfo.ServiceName))
                        {
                            var ServiceStatus = service.Status.ToString();
                            if (ServiceStatus == "Running")
                            {
                                service.Stop();
                                service.WaitForStatus(ServiceControllerStatus.Stopped);
                                service.Start();
                                service.WaitForStatus(ServiceControllerStatus.Running);
                            }
                            else
                            {
                                service.Start();
                                service.WaitForStatus(ServiceControllerStatus.Running);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                }
                ImageVisibility(false);
                MessageBox.Show("Back up settings saved successfully");
            }
            catch (Exception ex)
            {
                ImageVisibility(false);
                MessageBox.Show(ex.Message);
                log.Error(ex.Message);
            }
        }
Beispiel #26
0
        // used by bcrypt_pbkdf
        internal void ExpandState(byte[] key, byte[] data)
        {
            int keyLen = key.Length;

            for (int j = 0, i = 0; i < 16 + 2; i++)
            {
                uint temp =
                    (((uint)(key[j]) << 24) |
                     ((uint)(key[(j + 1) % keyLen]) << 16) |
                     ((uint)(key[(j + 2) % keyLen]) << 8) |
                     ((uint)(key[(j + 3) % keyLen])));
                P[i] = P[i] ^ temp;
                j    = (j + 4) % keyLen;
            }

            byte[] LR        = new byte[8];
            int    dataIndex = 0;
            int    dataLen   = data.Length;

            for (int i = 0; i < 16 + 2; i += 2)
            {
                for (int k = 0; k < 8; ++k)
                {
                    LR[k]    ^= data[dataIndex];
                    dataIndex = (dataIndex + 1) % dataLen;
                }

                BlockEncrypt(LR, 0, LR, 0);
                P[i]     = CipherUtil.GetIntBE(LR, 0);
                P[i + 1] = CipherUtil.GetIntBE(LR, 4);
            }

            for (int j = 0; j < 256; j += 2)
            {
                for (int k = 0; k < 8; ++k)
                {
                    LR[k]    ^= data[dataIndex];
                    dataIndex = (dataIndex + 1) % dataLen;
                }

                BlockEncrypt(LR, 0, LR, 0);
                S0[j]     = CipherUtil.GetIntBE(LR, 0);
                S0[j + 1] = CipherUtil.GetIntBE(LR, 4);
            }
            for (int j = 0; j < 256; j += 2)
            {
                for (int k = 0; k < 8; ++k)
                {
                    LR[k]    ^= data[dataIndex];
                    dataIndex = (dataIndex + 1) % dataLen;
                }

                BlockEncrypt(LR, 0, LR, 0);
                S1[j]     = CipherUtil.GetIntBE(LR, 0);
                S1[j + 1] = CipherUtil.GetIntBE(LR, 4);
            }
            for (int j = 0; j < 256; j += 2)
            {
                for (int k = 0; k < 8; ++k)
                {
                    LR[k]    ^= data[dataIndex];
                    dataIndex = (dataIndex + 1) % dataLen;
                }

                BlockEncrypt(LR, 0, LR, 0);
                S2[j]     = CipherUtil.GetIntBE(LR, 0);
                S2[j + 1] = CipherUtil.GetIntBE(LR, 4);
            }
            for (int j = 0; j < 256; j += 2)
            {
                for (int k = 0; k < 8; ++k)
                {
                    LR[k]    ^= data[dataIndex];
                    dataIndex = (dataIndex + 1) % dataLen;
                }

                BlockEncrypt(LR, 0, LR, 0);
                S3[j]     = CipherUtil.GetIntBE(LR, 0);
                S3[j + 1] = CipherUtil.GetIntBE(LR, 4);
            }
        }