示例#1
0
        public void AppPasswordEncryptDecryptTest()
        {
            SecureString masterPassword, appPassword;

            GetPasswords(out masterPassword, out appPassword);
            Crypto.Crypto crypto = new Crypto.Crypto();

            var          result           = crypto.EncryptAppPassword(appPassword, masterPassword);
            SecureString decryptedPassord = crypto.DecryptAppPassword(result.Item1, _appPasswordArray.Length, masterPassword, result.Item2);

            Assert.AreEqual(GetSecureStringValue(appPassword), GetSecureStringValue(decryptedPassord));
        }
        public ActionResult Login(string login, string senha)
        {
            string   senhaCrypto = new Crypto.Crypto().Encrypt(senha);
            USUARIOS uSUARIOS    = db.USUARIOS.FirstOrDefault(x => (x.CPF == login || x.EMAIL == login) && x.SENHA == senhaCrypto);

            if (uSUARIOS != null)
            {
                Session["Usuario"] = uSUARIOS;
                Session["Nome"]    = uSUARIOS.NOME;

                if (((USUARIOS)Session["Usuario"]).TIPO_ACESSO == 2)
                {
                    return(RedirectToAction("ConsultasMedico", "CONSULTAS"));
                }

                return(RedirectToAction("Agendadas", "CONSULTAS"));
            }

            return(RedirectToAction("Index", "LOGIN", new { mensagem = "Usuario ou senha invalidos!" }));
        }
        /// <summary>
        /// Enforce password security.
        /// </summary>
        /// <param name="PasswordFormat">Password format.</param>
        /// <param name="data">data</param>
        /// <param name="PassWord">Password.</param>
        /// <param name="PasswordSalt">Salt password.</param>
        public static void EnforcePasswordSecurity(int PasswordFormat, string data, out string PassWord, out string PasswordSalt)
        {
            Crypto.Crypto cryptObj = new Crypto.Crypto();
            string _Password="", _Salt="";
            switch (PasswordFormat)
            {
                case (int)PasswordFormats.CLEAR:
                case (int)PasswordFormats.ONE_WAY_HASHED:
                    cryptObj.GetHashAndSaltString(data, out _Password, out _Salt);
                    break;
                case (int)PasswordFormats.ENCRYPTED_AES:                   
                    _Password = Crypto.Crypto.Encrypt(data);
                    _Salt = "";
                    break;
                case (int)PasswordFormats.ENCRYPTED_RSA:
                    break;                

            }
            PassWord = _Password;
            PasswordSalt = _Salt;
        }
        public static void EnforcePasswordSecurity(int PasswordFormat, string data, out string PassWord, out string PasswordSalt)
        {
            Crypto.Crypto cryptObj = new Crypto.Crypto();
            string        _Password = "", _Salt = "";

            switch (PasswordFormat)
            {
            case (int)PasswordFormats.CLEAR:
            case (int)PasswordFormats.ONE_WAY_HASHED:
                cryptObj.GetHashAndSaltString(data, out _Password, out _Salt);
                break;

            case (int)PasswordFormats.ENCRYPTED_AES:
                _Password = Crypto.Crypto.Encrypt(data);
                _Salt     = "";
                break;

            case (int)PasswordFormats.ENCRYPTED_RSA:
                break;
            }
            PassWord     = _Password;
            PasswordSalt = _Salt;
        }
示例#5
0
        public async Task EncryptDecryptDataArrayTest()
        {
            byte[] bytes = new byte[_data.Length * sizeof(char)];
            Buffer.BlockCopy(_data.ToCharArray(), 0, bytes, 0, bytes.Length);
            SecureString masterPassword, appPassword;

            GetPasswords(out masterPassword, out appPassword);

            Crypto.Crypto crypto          = new Crypto.Crypto();
            var           appPasswordData = crypto.EncryptAppPassword(appPassword, masterPassword);

            byte[] encryptedResult = await crypto.EncryptDataArrayAsync(bytes, appPassword, appPasswordData.Item2);

            MemoryStream ms = new MemoryStream();

            ms.Write(encryptedResult, 0, encryptedResult.Length);
            ms.Position = 0;
            byte[] decryptedResult = crypto.DecryptMemoryStream(ms, appPassword, appPasswordData.Item2);
            Assert.IsTrue(bytes.Length == decryptedResult.Length && bytes.OrderBy(s => s).SequenceEqual(decryptedResult.OrderBy(s => s)));

            decryptedResult = await crypto.DecryptMemoryStreamAsync(ms, appPassword, appPasswordData.Item2);

            Assert.IsTrue(bytes.Length == decryptedResult.Length && bytes.OrderBy(s => s).SequenceEqual(decryptedResult.OrderBy(s => s)));
        }
示例#6
0
 public void GenerateSaltTest()
 {
     Crypto.Crypto crypto = new Crypto.Crypto();
     Assert.AreEqual(crypto.GenerateIterationsFromSalt(_passwordSalt), _passwordIterations);
 }
示例#7
0
 /// <summary>
 /// This method is required for Windows Forms designer support.
 /// Do not change the method contents inside the source code editor. The Forms designer might
 /// not be able to load this method if it was changed manually.
 /// </summary>
 private void InitializeComponent()
 {
     this.calculatemenu = new System.Windows.Forms.Button();
     this.cryptomenu    = new System.Windows.Forms.Button();
     this.networkmenu   = new System.Windows.Forms.Button();
     this.network1      = new Network.Network();
     this.calculate1    = new Calculate.Calculate();
     this.crypto1       = new Crypto.Crypto();
     this.SuspendLayout();
     //
     // calculatemenu
     //
     this.calculatemenu.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(255)))), ((int)(((byte)(128)))));
     this.calculatemenu.Location  = new System.Drawing.Point(15, 16);
     this.calculatemenu.Name      = "calculatemenu";
     this.calculatemenu.Size      = new System.Drawing.Size(87, 38);
     this.calculatemenu.TabIndex  = 0;
     this.calculatemenu.Text      = "Calculate";
     this.calculatemenu.UseVisualStyleBackColor = false;
     this.calculatemenu.Click += new System.EventHandler(this.CalculatemenuClick);
     //
     // cryptomenu
     //
     this.cryptomenu.BackColor = System.Drawing.Color.MintCream;
     this.cryptomenu.Location  = new System.Drawing.Point(124, 16);
     this.cryptomenu.Name      = "cryptomenu";
     this.cryptomenu.Size      = new System.Drawing.Size(87, 38);
     this.cryptomenu.TabIndex  = 2;
     this.cryptomenu.Text      = "Crypto";
     this.cryptomenu.UseVisualStyleBackColor = false;
     this.cryptomenu.Click += new System.EventHandler(this.CryptomenuClick);
     //
     // networkmenu
     //
     this.networkmenu.BackColor = System.Drawing.Color.PaleGoldenrod;
     this.networkmenu.Location  = new System.Drawing.Point(231, 16);
     this.networkmenu.Name      = "networkmenu";
     this.networkmenu.Size      = new System.Drawing.Size(87, 38);
     this.networkmenu.TabIndex  = 5;
     this.networkmenu.Text      = "Network";
     this.networkmenu.UseVisualStyleBackColor = false;
     this.networkmenu.Click += new System.EventHandler(this.NetworkmenuClick);
     //
     // network1
     //
     this.network1.BackColor = System.Drawing.Color.CadetBlue;
     this.network1.Location  = new System.Drawing.Point(26, 90);
     this.network1.Name      = "network1";
     this.network1.Size      = new System.Drawing.Size(813, 570);
     this.network1.TabIndex  = 7;
     //
     // calculate1
     //
     this.calculate1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(192)))), ((int)(((byte)(192)))));
     this.calculate1.Location  = new System.Drawing.Point(26, 90);
     this.calculate1.Name      = "calculate1";
     this.calculate1.Size      = new System.Drawing.Size(813, 570);
     this.calculate1.TabIndex  = 8;
     //
     // crypto1
     //
     this.crypto1.BackColor = System.Drawing.Color.LightSalmon;
     this.crypto1.Location  = new System.Drawing.Point(26, 90);
     this.crypto1.Name      = "crypto1";
     this.crypto1.Size      = new System.Drawing.Size(813, 570);
     this.crypto1.TabIndex  = 9;
     //
     // MainForm
     //
     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     this.AutoScaleMode       = System.Windows.Forms.AutoScaleMode.Font;
     this.BackColor           = System.Drawing.Color.Bisque;
     this.ClientSize          = new System.Drawing.Size(867, 682);
     this.Controls.Add(this.crypto1);
     this.Controls.Add(this.calculate1);
     this.Controls.Add(this.network1);
     this.Controls.Add(this.networkmenu);
     this.Controls.Add(this.cryptomenu);
     this.Controls.Add(this.calculatemenu);
     this.Name = "MainForm";
     this.Text = "EucliwoodBox";
     this.ResumeLayout(false);
 }