Skip to content

Commit

Permalink
364:改造并去掉内部的MD5(win2008下加密算法默认引发异常)(2016-09-08)
Browse files Browse the repository at this point in the history
365:去掉映射表的条件限制(支持更多的外部映射)(2016-09-11)
  • Loading branch information
cyq1162 committed Sep 11, 2016
1 parent 6f00d15 commit 07dd044
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Cache/AutoCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ private static string GetKey(AopEnum action, AopInfo aopInfo, string baseKey)
sb.Append(aopInfo.Where);
break;
}
return MD5.Get(sb.ToString());
return StaticTool.GetHashKey(sb.ToString());
}
#endregion

Expand Down
2 changes: 1 addition & 1 deletion Orm/SimpleOrmBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected void SetInit(Object entityInstance, string tableName, string conn, Aop
}
}

string key = tableName + MD5.Get(conn);
string key = tableName + StaticTool.GetHashKey(conn);
if (!CacheManage.LocalInstance.Contains(key))
{
DalType dal = DBTool.GetDalType(conn);
Expand Down
6 changes: 3 additions & 3 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[assembly: AssemblyTitle("CYQ.Data 数据层(ORM)框架 V5 版本")]
[assembly: AssemblyDescription("论坛:http://www.cyqdata.com/cyqdata")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("秋式软件 (2016-09-06)")]
[assembly: AssemblyCompany("秋式软件 (2016-09-11)")]
[assembly: AssemblyProduct("CYQ.Data 数据层(ORM)框架 V5 版本")]
[assembly: AssemblyCopyright("版权所有 (C) 秋式软件 2010-2020")]
[assembly: AssemblyTrademark("CYQ.Data")]
Expand All @@ -31,5 +31,5 @@
//
// 可以指定所有这些值,也可以使用“修订号”和“内部版本号”的默认值,
// 方法是按如下所示使用“*”:
[assembly: AssemblyVersion("5.6.5.2")]
[assembly: AssemblyFileVersion("5.6.5.2")]
[assembly: AssemblyVersion("5.6.5.3")]
[assembly: AssemblyFileVersion("5.6.5.3")]
2 changes: 1 addition & 1 deletion SQL/TableSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ internal static string GetSchemaKey(string tableName, string dbName, DalType dal
int end = key.LastIndexOf(')');
if (start > -1 && end > -1)//自定义table
{
key = "View" + Tool.MD5.Get(key);
key = "View" + StaticTool.GetHashKey(key);
}
else
{
Expand Down
3 changes: 2 additions & 1 deletion Tool/DBTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,8 @@ internal static string GetMapTableName(string conn, string tableName)
foreach (string item in list.Keys)
{
mapName = item.Replace("_", "").Replace("-", "").Replace(" ", "");//有奇葩用-符号和空格的。
if (item != mapName && !mapTable.ContainsKey(mapName))//只存档带-," ",_等符号的表名
//去掉原有的限制条件:(item != mapName 只存档带-," ",_等符号的表名 ),支持外部映射
if (!mapTable.ContainsKey(mapName))//
{
mapTable.Add(mapName.ToLower(), item);
}
Expand Down
33 changes: 6 additions & 27 deletions Tool/MD5.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,14 @@

namespace CYQ.Data.Tool
{
/// <summary>
/// 返回一个加密过的值
/// </summary>
internal class MD5
{
static Dictionary<string, string> md5Cache = new Dictionary<string, string>(32);
static System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
internal static string Get(string sourceString)
{
try
{
if (md5Cache.ContainsKey(sourceString))
{
return md5Cache[sourceString];
}
else
{
if (md5Cache.Count > 512)
{
md5Cache.Clear();
md5 = null;
md5Cache = new Dictionary<string, string>(64);
}
string value = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(sourceString)), 4, 8).Replace("-", "");
md5Cache.Add(sourceString, value);
return value;
}
}
catch
{
return sourceString;
}
}
//取消MD5,避开win2008的异常:此实现不是 Windows 平台 FIPS 验证的加密算法的一部
//static System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();

}
}
30 changes: 30 additions & 0 deletions Tool/StaticTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,5 +253,35 @@ internal static object ChangeType(object value, Type t)
return Convert.ChangeType(value, t);
}
}

#region 将字符串变HashKey
static Dictionary<string, string> hashKeyCache = new Dictionary<string, string>(32);
internal static string GetHashKey(string sourceString)
{
try
{
if (hashKeyCache.ContainsKey(sourceString))
{
return hashKeyCache[sourceString];
}
else
{
if (hashKeyCache.Count > 512)
{
hashKeyCache.Clear();
hashKeyCache = new Dictionary<string, string>(64);
}
string value = "K" + Math.Abs(sourceString.GetHashCode()) + sourceString.Length;
hashKeyCache.Add(sourceString, value);
return value;
}
}
catch
{
return sourceString;
}
}
#endregion

}
}
4 changes: 3 additions & 1 deletion 更新记录.txt
Original file line number Diff line number Diff line change
Expand Up @@ -576,4 +576,6 @@
360��AutoCache������MAction��Fill������ʱ�Ļ������ã��ijɿ�¡��������Fillָ��ͬһ���棩��2016-09-02)
361��MDataTable����Description���ԡ���2016-09-03)
362��DBTool��GetColumns���ӶԱ�ӳ���֧�֣�2016-09-05)
363�������ı����ݿ��ResetTable������ԭ��û����գ���2016-09-06)
363�������ı����ݿ��ResetTable������ԭ��û����գ���2016-09-06)
364�����첢ȥ���ڲ���MD5��win2008�¼����㷨Ĭ�������쳣����2016-09-08)
365��ȥ��ӳ������������ƣ�֧�ָ�����ⲿӳ�䣩��2016-09-11)

0 comments on commit 07dd044

Please sign in to comment.