Exemple #1
0
        public Usuario Decrypt(CoeusProjectContext Context = null)
        {
            if (this.Salt == null)
            {
                if (Context == null)
                {
                    Context = new CoeusProjectContext();
                }

                this.Salt = Context.Salt.Where(s => s.IdSalt == this.IdSalt).FirstOrDefault();
            }

            this.TxEmail  = SecurityFacade.Decrypt(TxEmail.Replace("*****@*****.**", ""), this.Salt.BtSalt);
            this.NmPessoa = SecurityFacade.Decrypt(NmPessoa, this.Salt.BtSalt);
            this.SnPessoa = SecurityFacade.Decrypt(SnPessoa, this.Salt.BtSalt);

            return(this);
        }
Exemple #2
0
        /// <summary>
        /// 0 = Create new Salt
        /// > 0 = Get Salt By Id
        /// </summary>
        public static Salt GetSalt(Int32 IdSalt = 0, CoeusProjectContext Context = null)
        {
            Salt    salt       = null;
            Boolean hasContext = true;

            if (Context == null)
            {
                hasContext = false;
                Context    = new CoeusProjectContext();
            }

            if (IdSalt == 0)
            {
                byte[] saltArray = new byte[16];
                Random rand      = new Random();
                salt = new Salt();

                for (int i = 0; i < 16; i++)
                {
                    saltArray[i] = (byte)rand.Next(0, 254);
                }

                salt.TxSalt = GetString(saltArray);
                Context.Salt.Add(salt);

                if (!hasContext)
                {
                    Context.SaveChanges();
                }
            }
            else
            {
                salt = Context.Salt.Where(s => s.IdSalt == IdSalt).FirstOrDefault();
            }
            return(salt);
        }