用户注册密码加密问题

wqb1979 2002-09-12 11:29:15
加精
用System.Web.Security的FormsAuthentication.HashPasswordForStoringInConfigFile方法好像是不可逆的,万一用户忘记密码想取回就麻烦了

我查了MSDN,可以用DESCryptoServiceProvider类、RC2CryptoServiceProvider类等,但是不知道怎么用
我要实现的是:可以把密码加密,存储入数据库,然后用户登录时或者忘记密码系统回发给用户时,解密还原给用户
...全文
212 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
wqb1979 2002-09-13
  • 打赏
  • 举报
回复
OK,结贴
wqb1979 2002-09-12
  • 打赏
  • 举报
回复
能给出个实例吗?
龙腾九霄 2002-09-12
  • 打赏
  • 举报
回复
最简单的加密,解密,转成ascii码或者转乘bit流。。
scent 2002-09-12
  • 打赏
  • 举报
回复
那就自己写一个加密解密函数了
killerwc 2002-09-12
  • 打赏
  • 举报
回复
xue xi
dotAge 2002-09-12
  • 打赏
  • 举报
回复
你的这种设计有问题,如果可逆,就会留下漏洞。
因此,如果用户忘了密码,应该核对其他信息(如生日或私人问题)再给他重设密码的机会即可。

你可以结贴了。
ameng_2002 2002-09-12
  • 打赏
  • 举报
回复
up
wqb1979 2002-09-12
  • 打赏
  • 举报
回复
好,我看看
zgh_ms 2002-09-12
  • 打赏
  • 举报
回复
相信下面的网页会对您有所帮助:

http://www.dotnet247.com/247reference/msgs/17/85028.aspx

-微软全球技术中心 -zgh

本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
zgh_ms 2002-09-12
  • 打赏
  • 举报
回复
感谢您的回复。

您可以参阅System.IO.MemoryStream. 把您的string转换为bytes,然后生成steam对象就可以使用了。

-微软全球技术中心 -zgh

本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
wqb1979 2002-09-12
  • 打赏
  • 举报
回复
多谢微软技术专家
可是DES.CreateEncryptor();的返回值类型是ICryptoTransform
如何把密文转换为字符串存入数据库字段中?
zgh_ms 2002-09-12
  • 打赏
  • 举报
回复
感谢您使用微软产品。

对明文密码使用Hash计算后,我们就不可能再把它转化为原来的明文了。

如果您要可逆的加密解密,请您使用.NET Framewwork System.Security.Cryptography命名空间下面所提供的加密Provider. 您可以选择使用DES, RSA等。

下面是一个C#控制台程序。读入明文文件,然后使用DES加密。

/////////////////////////////////////////////////////////////////////////////////////////////////////////

using System;
using System.IO;
using System.Security;
using System.Security.Cryptography;
using System.Text;

namespace CSEncryptDecrypt
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
//Must be 64 bits, 8 bytes.
private const string sSecretKey = "Password";

static void Main(string[] args)
{
EncryptFile("c:\\Sweep\\temp\\test.txt",
"c:\\Sweep\\temp\\Encrypted.txt",
sSecretKey);

Console.WriteLine("The file has been encrypted");

DecryptFile("c:\\Sweep\\temp\\Encrypted.txt",
"c:\\Sweep\\temp\\Decrypted.txt",
sSecretKey);

Console.WriteLine("The file has been decrypted");

}

static void EncryptFile(string sInputFilename,
string sOutputFilename,
string sKey)
{
FileStream fsInput = new FileStream(sInputFilename,
FileMode.Open,
FileAccess.Read);

FileStream fsEncrypted = new FileStream(sOutputFilename,
FileMode.Create,
FileAccess.Write);
DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
ICryptoTransform desencrypt = DES.CreateEncryptor();
CryptoStream cryptostream = new CryptoStream(fsEncrypted,
desencrypt,
CryptoStreamMode.Write);

byte[] bytearrayinput = new byte[fsInput.Length];
fsInput.Read(bytearrayinput, 0, bytearrayinput.Length);
cryptostream.Write(bytearrayinput, 0, bytearrayinput.Length);
cryptostream.Close();
fsInput.Close();
fsEncrypted.Close();
}

static void DecryptFile(string sInputFilename,
string sOutputFilename,
string sKey)
{
DESCryptoServiceProvider DES = new DESCryptoServiceProvider();
//A 64 bit key and IV is required for this provider.
//Set secret key For DES algorithm.
DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
//Set initialization vector.
DES.IV = ASCIIEncoding.ASCII.GetBytes(sKey);

//Create a file stream to read the encrypted file back.
FileStream fsread = new FileStream(sInputFilename,
FileMode.Open,
FileAccess.Read);
//Create a DES decryptor from the DES instance.
ICryptoTransform desdecrypt = DES.CreateDecryptor();
//Create crypto stream set to read and do a
//DES decryption transform on incoming bytes.
CryptoStream cryptostreamDecr = new CryptoStream(fsread,
desdecrypt,
CryptoStreamMode.Read);
//Print out the contents of the decrypted file.
StreamWriter fsDecrypted = new StreamWriter(sOutputFilename);
fsDecrypted.Write(new StreamReader(cryptostreamDecr).ReadToEnd());
fsDecrypted.Flush();
fsDecrypted.Close();
}

}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

System.Security.Cryptography下面提供了很多加密解密的方法。您可以根据自己的需要选择使用。更详细的信息,请您参阅下面的网站:

http://msdn.microsoft.com/library/dotnet/cpref/frlrfsystemsecuritycryptography.htm

希望对您有所帮助。

-微软全球技术中心 -zgh

本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
sunxiaoli 2002-09-12
  • 打赏
  • 举报
回复
gz
xhan2000 2002-09-12
  • 打赏
  • 举报
回复
base64可以解密

62,248

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧