最近我有發生一個網頁程式問題,這個程式是寄信程式,我把寄信的帳號密碼用AES方式加密後存到Web.Config,然後再AES解密讀出來,本來用很久了,都沒有問題,結果最近竟然突然不能寄信了,最後我發現問題就出在AES解密,解密出來竟然是空值,這樣子Email Adress變成空值就不能寄信了,可是明明已經用了一個月最近才突然出問題,程式語法如下:
public string aesDecryptBase64(string SourceStr)
{
string decrypt = "";
try
{
AesCryptoServiceProvider aes = new AesCryptoServiceProvider();
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
SHA256CryptoServiceProvider sha256 = new SHA256CryptoServiceProvider();
byte[] key = sha256.ComputeHash(Encoding.UTF8.GetBytes(CryptoKey));
byte[] iv = md5.ComputeHash(Encoding.UTF8.GetBytes(CryptoKey));
aes.Key = key;
aes.IV = iv;
byte[] dataByteArray = Convert.FromBase64String(SourceStr);
using (MemoryStream ms = new MemoryStream())
{
using (CryptoStream cs = new CryptoStream(ms, aes.CreateDecryptor(), CryptoStreamMode.Write))
{
cs.Write(dataByteArray, 0, dataByteArray.Length);
cs.FlushFinalBlock();
decrypt = Encoding.UTF8.GetString(ms.ToArray());
}
}
}
catch (Exception ex)
{
logger.Debug("錯誤function:aesDecryptBase64,錯誤訊息:" + ex.InnerException + ex.ToString());
}
return decrypt;
}
最近突然解密出來變成空值,我真的不知道為什麼會這樣,有高手知道可以回答我嗎?謝謝
會不會是 System.Security.Cryptography.Algorithms.dll 被更動了?