Telerik Sitefinity密码哈希function

我有一个表格,其中包含Telerik Sitefinity系统的登录凭据。 我想使用相同的登录凭据,但使用不具有Sitefinity库的其他应用程序。 我正在努力使用密码编码,密码编码设置为Hash(默认为SHA1算法)。

我尝试使用以下代码对密码进行编码,但它与Sitefinity生成的内容不匹配。

public string EncodePassword(string pass, string salt) { byte[] bytes = Encoding.Unicode.GetBytes(pass); byte[] src = Convert.FromBase64String(salt); byte[] dst = new byte[src.Length + bytes.Length]; Buffer.BlockCopy(src, 0, dst, 0, src.Length); Buffer.BlockCopy(bytes, 0, dst, src.Length, bytes.Length); HashAlgorithm algorithm = HashAlgorithm.Create("SHA1"); byte[] inArray = algorithm.ComputeHash(dst); return Convert.ToBase64String(inArray); } 

例:

密码:password111

盐:94EBE09530D9F5FAE3D002A4BF262D2F(保存在SF用户表中)

上面的函数哈希:8IjcFO4ad8BdkD40NJcgD0iGloU =

SF生成的表中的哈希值:A24GuU8OasJ2bicvT / E4ZiKfAT8 =

如果SF以不同方式生成编码密码,但我无法找到任何结果,我在线搜索。 如何在没有SF库的情况下使用SF创建的登录凭据?

您是对的,Sitefinity使用SHA1算法,但您需要从配置设置中使用其他ValidationKey。

这里是代码的工作示例:

 private static bool CheckValidPassword(string password) { //from sf_users column [salt] var userSalt = "420540B274162AA093FDAC86894F3172"; //from sf_users column [passwd] var userPassword = "a99j8I0em8DOP1IAJO/O7umQ+H0="; //from App_Data\Sitefinity\Configuration\SecurityConfig.config attribute "validationKey" var validationKey = "862391D1B281951D5D92837F4DB9714E0A5630F96483FF39E4307AE733424C557354AE85FF1C00D73AEB48DF3421DD159F6BFA165FF8E812341611BDE60E0D4A"; return userPassword == ComputeHash(password + userSalt, validationKey); } internal static string ComputeHash(string data, string key) { byte[] hashKey = HexToBytes(key); HMACSHA1 hmacshA1 = new HMACSHA1(); hmacshA1.Key = hashKey; var hash = hmacshA1.ComputeHash(Encoding.Unicode.GetBytes(data)); return Convert.ToBase64String(hash); } public static byte[] HexToBytes(string hexString) { byte[] numArray = new byte[hexString.Length / 2]; for (int index = 0; index < numArray.Length; ++index) numArray[index] = Convert.ToByte(hexString.Substring(index * 2, 2), 16); return numArray; }