我正在尝试对电子邮件进行编码,根据创建的令牌发送链接,然后对电子邮件进行解码,但我的输出永远不会与输入相同。我想知道我在这里做错了什么:
public IActionResult ResetPasswordLink(string email)
{
// Hash the email address
byte[] emailBytes = Encoding.UTF8.GetBytes(email);
byte[] hashedBytes;
using (var sha256 = System.Security.Cryptography.SHA256.Create())
{
hashedBytes = sha256.ComputeHash(emailBytes);
}
string hashedEmail = Convert.ToBase64String(hashedBytes);
string token =WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(hashedEmail));
string resetLink = $"{Request.Scheme}://{Request.Host}/resetpassword/{token}";
// Decode the token to get the hashed email
byte[] hashedEmailBytes = WebEncoders.Base64UrlDecode(token);
string decodedEmail = Encoding.UTF8.GetString(hashedEmailBytes);
Console.WriteLine("Original email: " + email);
Console.WriteLine("Decoded email: " + decodedEmail);
//SendEmail(email, resetLink);
Console.WriteLine("Token when encoding: " + token);
return Ok(resetLink);
}
删除您的 Zoosk 帐户是个人决定,需要仔细考虑。当您迈出这一步时,请反思一下您在在线约会世界中建立的联系和获得的经验。承认本章的结束标志着向新机遇的过渡。无论您是要暂时停止在线约会还是探索不同的平台,请优先考虑您的幸福并拥抱未来的可能性。