gpt4 book ai didi

asp.net - 从 ASP.NET 2.0 成员身份解密 'Encrypted' 密码

转载 作者:行者123 更新时间:2023-12-03 14:57:51 26 4
gpt4 key购买 nike

我需要解密位于我的 aspnet_Membership 表中的加密(非散列)密码。在那个数据库中,我看到 Password (Encrypted) 和 PasswordSalt 字段,我可以查看我的 web.config 以找到 machinekey >decryptionKey(validation="SHA1"decryption="AES")。

注意:我很想使用散列密码,但出于业务原因,我需要能够使用成员(member)的密码,用于进出其他远程系统的 SSO,因此使用加密(绝对不使用 Clear - yukky!)

鉴于所有这些,当然有一种方法可以将密码检索为清晰,简单易读的文本,即解密,但我很难找到任何网站,或者在 stackoverflow 上回答(我正在查看所有“类似的问题”和“具有类似标题的问题”在这里)解释了如何做到这一点。

我找到了 MembershipProvider.DecryptPassword Method页面,但我仍然无法弄清楚如何在我的代码中实际使用它。我还通过 Google 找到了其他页面,但大多数密码解密示例似乎都没有将 salt 和 decrytionKey 考虑在内。

有没有人有一个直接的例子来从各自的位置选择密码、密码盐和解密 key ,并使用它们来解密 ASP.NET 2.0 成员(member)加密密码?

最佳答案

创建一个从 SqlMembershipProvider 继承的类,您可以在其中调用解密。

您需要的所有代码都可以在 this article by Naveen Kohli 中找到。 :

After looking through the code in reflector, I saw that Microsoft providers decrypts in two steps. The encrypted password is actually a Base64 conversion of encrypted data. So first it converts it back from Base64 and then calls DecryptPassword method. I just did the easiest thing. Copied the code from Microsoft implementation, removed all the checks it was doing and then used it. Following class is an example of a class derived form SqlMembershipProvider with a method that just returns me password in clear text for a given encrypted password.

namespace MembershipPasswordRecover
{
public class NetFourMembershipProvider : SqlMembershipProvider
{
public string GetClearTextPassword(string encryptedPwd)
{
byte[] encodedPassword = Convert.FromBase64String(encryptedPwd);
byte[] bytes = this.DecryptPassword(encodedPassword);
if (bytes == null)
{
return null;
}
return Encoding.Unicode.GetString(bytes, 0x10, bytes.Length - 0x10);

}
}
}

static void Main(string[] args)
{
var passwordManager = new NetFourMembershipProvider();
var clearPWd = passwordManager.GetClearTextPassword("encryptedpasswordhere");
Console.WriteLine(clearPWd);
}

关于asp.net - 从 ASP.NET 2.0 成员身份解密 'Encrypted' 密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6231942/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com