Beispiel #1
0
        /// <summary>
        ///  构造函数...
        /// </summary>
        /// <param name="clientMsg"></param>
        /// <param name="msgLever"></param>
        /// <param name="innerException"></param>
        public APPException(string clientMsg, APPMessageType msgLever, Exception innerException)
            : base(clientMsg, innerException)
        {
            _MsgLever = msgLever;
            string msg = clientMsg;

            if (innerException != null)
            {
                string innerMsg = string.Empty;
                if (innerException is APPException)
                {
                    APPException appEx = innerException as   APPException;
                    _MsgLever = appEx.MsgLever;
                    innerMsg  = appEx.Message;
                }
                else
                {
                    try {
                        getErrMessage(innerException, ref innerMsg);
                    }
                    catch { }
                }
                TraceEx.Write(innerMsg, APPMessageType.SysErrInfo);
                if (!string.IsNullOrEmpty(innerException.StackTrace))
                {
                    TraceEx.Write(innerException.StackTrace);
                }
            }
            TraceEx.Write(msg, msgLever);
        }
Beispiel #2
0
        /// <summary>
        /// 加密字符窜
        /// </summary>
        /// <param name="pEncryptedStr"></param>
        /// <returns></returns>
        public static string EncryptString(string encryptedStr)
        {
            //des进行加密
            DESCryptoServiceProvider desc = new DESCryptoServiceProvider();
            //产生key
            PasswordDeriveBytes db = new PasswordDeriveBytes(KEY_ENCRYPT, null);

            byte[] key = db.GetBytes(8);
            //存储加密后的数据
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(ms, desc.CreateEncryptor(key, key), CryptoStreamMode.Write);

            //取到密码的字节流
            try {
                byte[] data = Encoding.UTF8.GetBytes(encryptedStr);
                //进行加密
                cs.Write(data, 0, data.Length);
                cs.FlushFinalBlock();
                //取加密后的数据
                byte[] res = ms.ToArray();
                return(Convert.ToBase64String(res));
            }
            catch {
                TraceEx.Write("字符窜" + encryptedStr + "加密不成功。");
                return(null);
            }
        }
Beispiel #3
0
 /// <summary>
 /// 构造函数...
 /// </summary>
 /// <param name="pMsg">抛出异常的信息</param>
 /// <param name="pMsgLever">异常信息的类型等级</param>
 public APPException(string clientMsg, APPMessageType msgLever, string errorCode)
     : base(clientMsg)
 {
     _MsgLever  = msgLever;
     _ErrorCode = errorCode;
     TraceEx.Write(clientMsg, msgLever);
 }
Beispiel #4
0
        /// <summary>
        /// 解密字符窜
        /// </summary>
        /// <param name="pDecryptStr"></param>
        /// <returns></returns>
        public static string DecryptString(string decryptStr)
        {
            DESCryptoServiceProvider desc = new DESCryptoServiceProvider();
            //产生key
            PasswordDeriveBytes db = new PasswordDeriveBytes(KEY_ENCRYPT, null);

            byte[] key = db.GetBytes(8);
            //存储解密后的数据
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(ms, desc.CreateDecryptor(key, key), CryptoStreamMode.Write);

            //取到加密后的数据的字节流,如果是保存到文件
            try {
                byte[] databytes = Convert.FromBase64String(decryptStr);
                //解密数据
                cs.Write(databytes, 0, databytes.Length);
                cs.FlushFinalBlock();
                byte[] res = ms.ToArray();
                //返回解密后的数据,这里返回的数据应该和参数pwd的值相同。
                return(System.Text.Encoding.UTF8.GetString(res));
            }
            catch {
                TraceEx.Write("字符窜" + decryptStr + "解密不成功。");
                return(null);
            }
        }