Exemplo n.º 1
0
        public ActionResult Confirm(string hash)
        {
            try
            {
                hash = CryptAES.Decrypt(hash);

                JObject json = JObject.Parse(hash);

                DateTime dateCreate = (DateTime)json["dateCreate"];
                DateTime dateExpire = (DateTime)json["dateExpire"];
                string   Method     = (string)json["Method"];
                int      userId     = (int)json["userId"];

                if (Method != "ConfirmEmail")
                {
                    throw new Exception("Hash inválido para esse tipo de operação");
                }

                if (DateTime.Now > dateExpire)
                {
                    throw new Exception("Tempo limite expirado. Por favor, gere outra chave de validação");
                }

                ViewBag.MessageSuccess = "Email confirmado com sucesso!";
                return(View());
            }
            catch (Exception E)
            {
                ViewBag.ErrorToConfirm = E.Message;
                return(View("ErrorConfirm"));
            }
        }
Exemplo n.º 2
0
        public async Task <ActionResult> ConfirmRecover(string hash)
        {
            try
            {
                hash = CryptAES.Decrypt(hash);

                JObject json = JObject.Parse(hash);

                DateTime dateCreate = (DateTime)json["dateCreate"];
                DateTime dateExpire = (DateTime)json["dateExpire"];
                string   Method     = (string)json["Method"];
                decimal  userId     = (decimal)json["userId"];

                if (Method != "RecoverPassword")
                {
                    throw new Exception("Hash inválido para esse tipo de operação");
                }

                if (DateTime.Now > dateExpire)
                {
                    throw new Exception("Tempo limite expirado. Por favor, gere outra solicitação para recuperar a senha");
                }

                var user = await _usuarioRepo.GetAsync(userId);

                if (user == null)
                {
                    throw new Exception("Usuário inválido.");
                }

                var userVM = user.ToVM();
                userVM.Senha = "";

                return(View(userVM));
            }
            catch (Exception E)
            {
                ViewBag.ErrorToConfirm = E.Message;
                return(View("ErrorConfirm"));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Actions to do when user clicks the 'Go' button
        /// </summary>
        /// <param name="sender">Sender of Click event</param>
        /// <param name="e">Arguments for Click event</param>
        private void btGoClick(object sender, EventArgs e)
        {
            // No text to crypt/decrypt? finish
            if (txtText.Text == "")
            {
                return;
            }
            // According to selected crypt algorithm...
            switch (cbType.SelectedIndex)
            {
            case 0:     // CryptStream3DES
                // No key and initializer values? finish
                if ((txtKey.Text == "") || (txtIV.Text == ""))
                {
                    return;
                }
                // If we are encrypting, use according texts for encrypt and decrypt
                if (tbSide.Value == 0)
                {
                    txtCrypt.Text   = CryptStream3DES.Encrypt(txtText.Text, txtKey.Text, txtIV.Text);
                    txtDecrypt.Text = CryptStream3DES.Decrypt(txtCrypt.Text, txtKey.Text, txtIV.Text);
                }
                else
                {
                    // If we are decrypting, take the inverse text values
                    txtCrypt.Text   = CryptStream3DES.Decrypt(txtText.Text, txtKey.Text, txtIV.Text);
                    txtDecrypt.Text = CryptStream3DES.Encrypt(txtCrypt.Text, txtKey.Text, txtIV.Text);
                }
                break;

            case 1:     // Crypt3DES
                // No key? finish
                if (txtKey.Text == "")
                {
                    return;
                }
                // If we are encrypting, use according text for encrypt and decrypt
                if (tbSide.Value == 0)
                {
                    txtCrypt.Text   = Crypt3DES.Encrypt(txtText.Text, txtKey.Text);
                    txtDecrypt.Text = Crypt3DES.Decrypt(txtCrypt.Text, txtKey.Text);
                }
                else
                {
                    // If we are decrypting, use the inverse text values
                    txtCrypt.Text   = Crypt3DES.Decrypt(txtText.Text, txtKey.Text);
                    txtDecrypt.Text = Crypt3DES.Encrypt(txtCrypt.Text, txtKey.Text);
                }
                break;

            case 2:     // CryptAES
                // No key and initializer? finish
                if ((txtKey.Text == "") || (txtIV.Text == ""))
                {
                    return;
                }
                // Use right texts to encrypt/decrypt, based on our setup (also use provided key and salt)
                if (tbSide.Value == 0)
                {
                    txtCrypt.Text   = CryptAES.Encrypt(txtText.Text, txtKey.Text, txtIV.Text);
                    txtDecrypt.Text = CryptAES.Decrypt(txtCrypt.Text, txtKey.Text, txtIV.Text);
                }
                else
                {
                    txtCrypt.Text   = CryptAES.Decrypt(txtText.Text, txtKey.Text, txtIV.Text);
                    txtDecrypt.Text = CryptAES.Encrypt(txtCrypt.Text, txtKey.Text, txtIV.Text);
                }
                break;

            case 3:     // UUCode
                // Apply encoding/decoding to right texts according to setup
                if (tbSide.Value == 0)
                {
                    txtCrypt.Text   = UUCoder.Encode(txtText.Text);
                    txtDecrypt.Text = UUCoder.Decode(txtCrypt.Text);
                }
                else
                {
                    txtCrypt.Text   = UUCoder.Decode(txtText.Text);
                    txtDecrypt.Text = UUCoder.Encode(txtCrypt.Text);
                }
                break;

            case 4:     // Mime/Base64
                // Apply encoding/decoding to right texts according to setup
                if (tbSide.Value == 0)
                {
                    txtCrypt.Text   = Base64.EncodeString(txtText.Text);
                    txtDecrypt.Text = Base64.DecodeString(txtCrypt.Text);
                }
                else
                {
                    txtCrypt.Text   = Base64.DecodeString(txtText.Text);
                    txtDecrypt.Text = Base64.EncodeString(txtCrypt.Text);
                }
                break;

            case 5:     // Adler32
                // Calculate hash for given text...
                txtCrypt.Text = string.Format("{0:X}", Adler32.AdlerHash(txtText.Text));
                break;

            case 6:     // CRC16
                // Calculate hash for given text...
                txtCrypt.Text = string.Format("{0:X}", CRC16.Hash(txtText.Text));
                break;

            case 7:     // CRC32
                // Calculate hash for given text...
                txtCrypt.Text = string.Format("{0:X}", CRC32.Hash(txtText.Text));
                break;

            case 8:     // CRC64
                // Calculate hash for given text...
                txtCrypt.Text = string.Format("{0:X}", CRC64.Hash(txtText.Text));
                break;

            case 9:     // Salsa20
                // No key and initializer? finish
                if ((txtKey.Text == "") || (txtIV.Text == ""))
                {
                    return;
                }
                // Use cryptor to encrypt/decrypt data, according to setup
                using (var salsa = new CryptSalsa(txtKey.Text, txtIV.Text))
                {
                    // Encrypt -> Decrypt
                    if (tbSide.Value == 0)
                    {
                        txtCrypt.Text   = salsa.Encrypt(txtText.Text);
                        txtDecrypt.Text = salsa.Decrypt(txtCrypt.Text);
                    }
                    else
                    {
                        // Or Decrypt -> Encrypt
                        txtCrypt.Text   = salsa.Decrypt(txtText.Text);
                        txtDecrypt.Text = salsa.Encrypt(txtCrypt.Text);
                    }
                }
                break;

            case 10:     // ChaCha20
                // No key/initializer? finish
                if ((txtKey.Text == "") || (txtIV.Text == ""))
                {
                    return;
                }
                // Use cryptor to encrypt/decrypt data, according to setup
                using (var chacha = new CryptChaCha20(txtKey.Text, txtIV.Text))
                {
                    // Encrypt -> Decrypt
                    if (tbSide.Value == 0)
                    {
                        txtCrypt.Text   = chacha.Encrypt(txtText.Text);
                        txtDecrypt.Text = chacha.Decrypt(txtCrypt.Text);
                    }
                    else
                    {
                        // Or Decrypt -> Encrypt
                        txtCrypt.Text   = chacha.Decrypt(txtText.Text);
                        txtDecrypt.Text = chacha.Encrypt(txtCrypt.Text);
                    }
                }
                break;

            case 11:     // RSA
                // if no key/initializer value, finish
                if ((txtKey.Text == "") || (txtIV.Text == ""))
                {
                    return;
                }
                using (var rsa = new CryptRSA(txtKey.Text, keySizes[cbKeySize.SelectedIndex]))
                {
                    // Use private key?
                    if (cbPrivateKey.Checked)
                    {
                        // Use cryptor to encrypt/decrypt data, according to setup
                        if (tbSide.Value == 0)
                        {
                            // Encrypt -> Decrypt
                            txtCrypt.Text   = rsa.PrivateEncrypt(txtText.Text);
                            txtDecrypt.Text = rsa.PublicDecrypt(txtCrypt.Text);
                        }
                        else
                        {
                            // Or Decrypt -> Encrypt
                            txtCrypt.Text   = rsa.PublicDecrypt(txtText.Text);
                            txtDecrypt.Text = rsa.PrivateEncrypt(txtCrypt.Text);
                        }
                    }
                    else
                    {
                        // Nope, use public key...
                        // Use cryptor to encrypt/decrypt data, according to setup
                        if (tbSide.Value == 0)
                        {
                            // Encrypt -> Decrypt
                            txtCrypt.Text   = rsa.PublicEncrypt(txtText.Text);
                            txtDecrypt.Text = rsa.PrivateDecrypt(txtCrypt.Text);
                        }
                        else
                        {
                            // Or Decrypt -> Encrypt
                            txtCrypt.Text   = rsa.PrivateDecrypt(txtText.Text);
                            txtDecrypt.Text = rsa.PublicEncrypt(txtCrypt.Text);
                        }
                    }
                }
                break;

            case 12:     // Blowfish
                // No key? finish
                if (txtKey.Text == "")
                {
                    return;
                }
                // Use cryptor to encrypt/decrypt data, according to setup
                using (var blowfish = new CryptBlowfish(txtKey.Text))
                {
                    // Encrypt -> Decrypt
                    if (tbSide.Value == 0)
                    {
                        txtCrypt.Text   = blowfish.Encrypt(txtText.Text);
                        txtDecrypt.Text = blowfish.Decrypt(txtCrypt.Text);
                    }
                    else
                    {
                        // Or Decrypt -> Encrypt
                        txtCrypt.Text   = blowfish.Decrypt(txtText.Text);
                        txtDecrypt.Text = blowfish.Encrypt(txtCrypt.Text);
                    }
                }
                break;
            }
        }