2009-10-19 87 views
-1

我有一個SQL數據庫存儲通過.NET應用程序加密的密碼,我需要通過ColdFusion應用程序解密。我似乎無法爲CF解密工作設定更好的東西。任何幫助將不勝感激。謝謝。幫助在ColdFusion中創建密碼在.NET中創建密碼

的.NET解密代碼:

public string Decrypt(string input) 
{ 
    try 
    { 
    DESCryptoServiceProvider des = new DESCryptoServiceProvider(); 

    int ZeroBasedByteCount = (input.Length/2); 

    //Put the input string into the byte array 
    byte[] inputByteArray = new byte[ZeroBasedByteCount]; 

    int i; 
    int x; 

    for (x = 0;x<ZeroBasedByteCount;x++) 
    { 
    i = (Convert.ToInt32(input.Substring(x * 2, 2), 16)); 
    inputByteArray[x] = (byte)i; 
    } 

    //Create the crypto objects 
    des.Key = ASCIIEncoding.ASCII.GetBytes(key); 
    des.IV = ASCIIEncoding.ASCII.GetBytes(key); 
    MemoryStream ms = new MemoryStream(); 
    CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write); 

    //Flush the data through the crypto stream into the memory stream 
    cs.Write(inputByteArray, 0, inputByteArray.Length); 
    cs.FlushFinalBlock(); 

    //Get the decrypted data back from the memory stream 
    StringBuilder ret = new StringBuilder(); 

    foreach(byte b in ms.ToArray()) 
    { 
    ret.Append((char)b); 
    } 

    return ret.ToString(); 

    } 
    catch(Exception ex) 
    { 
    throw(ex); 
    return null; 
    } 
} 
+0

關鍵變量來自哪裏? – 2009-10-19 18:37:31

+3

雖然它沒有解決這個特定的問題,但你不需要解密密碼 - 他們應該總是使用單向散列,並檢查你加密這些密碼的企圖並比較兩個加密值。 – 2009-10-19 18:38:59

+1

@彼得Boughton:阿門對此。 – Tomalak 2009-10-19 19:17:44

回答

0

你看了docs for the CF Decrypt function和確定什麼價值,你需要的編碼,IVorSalt,和/或迭代變量? (它看起來像算法是DES。)

+0

我讀過文檔,它看起來像是我處理密碼和密鑰,這是我從舊系統中得到的,因此它們在CF中提供的值與它們在.NEt中的值相同。 CF過程需要給出與 - – KnightStalker 2009-10-19 22:44:44

+0

int ZeroBasedByteCount =(input.Length/2)相同的值; //將輸入字符串放入字節數組byte [] inputByteArray = new byte [ZeroBasedByteCount]; int i; int x; for(x = 0; x KnightStalker 2009-10-19 22:45:56