問題描述
我有一個密碼哈希,它存儲在一個表中,并由以下冷融合腳本放在那里-
I have a password hash that is stored in a table and is put there by the following coldfusion script-
#Hash(Encrypt(Form.UserPassword,GetSiteVars.EnCode))#
我正在嘗試在 c# 應用程序中添加一些外部功能.我希望能夠利用已經存在的數據,以便對用戶進行身份驗證.有誰知道我如何在 c# 中復制上述冷融合代碼?
I am trying to add some outside functionality within a c# application. I would like to be able to take advantage of the data that already exists so that I can authenticate users. Does anyone know how I can replicate the above coldfusion code in c#?
感謝您的任何想法.
推薦答案
我將把原來的答案內容留在下面以供歷史參考,但需要注意的是,這不是對原始問題的有效答案.
I'll leave the original answer content below for historical reference, but it should be noted that this is NOT a working answer to the original question.
相反,請參閱 2011 年 1 月 @Terrapin 在此線程中投票最多的答案.我希望 OP 看到這一點并可以更改接受的答案.哎呀,我什至會標記模組,看看是否可以對此做任何事情.
Instead, see the top-voted answer in this thread, by @Terrapin in January 2011. I hope the OP sees this and can change the accepted answer. Heck, I'll even flag the mods to see if anything can be done about this.
根據 Edward Smith 的回答和 czuroski 的后續評論,這是我的解決方案.
To build on the answer by Edward Smith, and the follow-up comments by czuroski, here is my solution.
首先,你需要一個 C# 中的 XOR 函數,我取自 這里并稍作修改.
First, you need an XOR function in C#, which I've taken from here and modified slightly.
using System;
using System.Collections.Generic;
using System.Text;
namespace SimpleXOREncryption
{
public static class EncryptorDecryptor
{
public static string EncryptDecrypt(string textToEncrypt, int key)
{
StringBuilder inSb = new StringBuilder(textToEncrypt);
StringBuilder outSb = new StringBuilder(textToEncrypt.Length);
char c;
for (int i = 0; i < textToEncrypt.Length; i++)
{
c = inSb[i];
c = (char)(c ^ key);
outSb.Append(c);
}
return outSb.ToString();
}
}
}
然后,取 XOR 的結果并進行 base-64 編碼.獲得該字符串后,MD5 對其進行哈希處理.結果應該與原始代碼片段的結果相匹配:
Then, take the result of the XOR and base-64 encode it. After you have that string, MD5 hash it. The result should match the result from the original code snippet:
#Hash(Encrypt(Form.UserPassword,GetSiteVars.EnCode))#
這篇關于比較 C# 和 ColdFusion 之間的密碼哈希 (CFMX_COMPAT)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!