public async Task <bool> SendRecover(EmailFormModel emailFormModel, int UserId) { //cria o hash com os dados Dictionary <string, string> dict = new Dictionary <string, string> { { "dateCreate", DateTime.Now.ToString("o") }, { "dateExpire", DateTime.Now.AddHours(24).ToString("o") }, { "userId", UserId.ToString() }, { "Method", "RecoverPassword" } }; var hash = CryptAES.Encrypt(dict.ToDebugString()); var message = new MailMessage(); message.To.Add(new MailAddress(emailFormModel.FromEmail, emailFormModel.FromName)); message.From = new MailAddress(_MyEmail, "JDKB - Base de Conhecimento"); message.Subject = "Recuperar senha"; message.Body = "<!DOCTYPE html>" + "<html>" + "<head>" + "<title>JDKB - Recuperar senha</title>" + "</head>" + "<body style=\"margin:0;padding:10px;font-family:Helvetica,Arial,sans-serif;font-weight:300;background-color:#ffffff;max-width:600px;margin:0 auto;text-align:center;color:#333333;\">" + "<h2 style=\"color:#0fad00\">Olá " + emailFormModel.FromName + "</h2>" + "<p style=\"font-size:20px;color:#5C5C5C;\">" + " Para redefinir sua senha, clique no link abaixo: (esse link vai expirar em 24 horas):" + "</p>" + "<a href=\"" + GetURL() + "Recoverconfirm?hash=" + hash + "\" target=\"_blank\" style=\"background-color:#1979bb;display:inline-block;padding:7px 15px;border-radius:5px;color:#fff;text-decoration:none;margin-bottom:40px\">Redefinir minha senha</a>" + "<p style=\"font-size:10px;color:gray;\">" + "Se você não solicitou a recuperação da senha, favor desconsiderar esse email" + "</p>" + "</body>" + "</html>"; message.IsBodyHtml = true; using (var _smtp = GetSmtp()) { await _smtp.SendMailAsync(message); } return(await Task.FromResult(true)); }
/// <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; } }