我有以下代码。它一直在我的暂存和预生产环境以及生产环境中工作。
它如何突然停止仅在生产环境中工作。它仍然适用于预生产和生产。
它抛出“哈希值不匹配”错误,这意味着存储哈希!= calcHash。
任何想法为什么这可能只发生在 3 个环境中?
static public string StrDec(string value, string key)
{
String dataValue = "";
String calcHash = "";
String storedHash = "";
MACTripleDES mac3des = new MACTripleDES();
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
mac3des.Key = md5.ComputeHash(Encoding.UTF8.GetBytes(key));
try
{
string strRemoveSpace = value.Replace(" ", "+");
dataValue = Encoding.UTF8.GetString(System.Convert.FromBase64String(strRemoveSpace.Split(System.Convert.ToChar("-"))[0]));
storedHash = Encoding.UTF8.GetString(System.Convert.FromBase64String(strRemoveSpace.Split(System.Convert.ToChar("-"))[1]));
calcHash = Encoding.UTF8.GetString(mac3des.ComputeHash(Encoding.UTF8.GetBytes(dataValue)));
if (storedHash != calcHash)
{
//Throw exception because data was corrupted here
throw new ArgumentException("Hash value does not match");
}
}
catch (System.Exception ex)
{
//Catch System.Exception here
}
return dataValue;
}