Ejemplo n.º 1
0
        /// <summary> 实体加密(空值不加密)
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="t">返回加密后的实体</param>
        /// <returns></returns>
        public static T EncModel <T>(T t)
        {
            T model = t;

            foreach (PropertyInfo item in t.GetType().GetProperties())
            {
                if (item.PropertyType.FullName == "System.String")
                {
                    object obj = item.GetValue(t, new object[] { });
                    if (obj != null && !string.IsNullOrEmpty(obj.ToString()))
                    {
                        string value = obj.ToString();
                        value = Secret.Encrypt3DES_UTF8(value, GlobalStaticObj_YT.KeySecurity_YT);
                        item.SetValue(model, value, null);
                    }
                }
                else if (item.PropertyType == typeof(byte[]))
                {
                    //object obj = item.GetValue(t, new object[] { });
                    //if (obj != null)
                    //{
                    //    byte[] objValue = (byte[])obj;
                    //    string value
                    //    objValue = Secret.Encrypt3DES(objValue, GlobalStaticObj_YT.KeySecurity_YT, Encoding.UTF8);
                    //    item.SetValue(model, objValue, null);
                    //}
                }
            }
            return(model);
        }