我有一個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;
}
}
關鍵變量來自哪裏? – 2009-10-19 18:37:31
雖然它沒有解決這個特定的問題,但你不需要解密密碼 - 他們應該總是使用單向散列,並檢查你加密這些密碼的企圖並比較兩個加密值。 – 2009-10-19 18:38:59
@彼得Boughton:阿門對此。 – Tomalak 2009-10-19 19:17:44