Beispiel #1
0
 /// <summary>
 /// 返回授权信息明文,返回的数组0为用户名明文,1为密码明文
 /// </summary>
 /// <param name="message">传入的请求消息</param>
 /// <returns>授权明文信息,0为用户名明文,1为密码明文</returns>
 public static string[] GetAuthorization(string message)
 {
     string[] result   = new string[2];
     string[] recArray = message.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
     foreach (var item in recArray)
     {
         //授权信息
         if (item.IndexOf("Authorization") >= 0)
         {
             string base64Code = item.Substring(item.IndexOf("Basic ") + 6, item.Length - item.IndexOf("Basic ") - 6);
             string code       = Base64Helper.Base64Decode(base64Code);
             result[0] = code.Substring(0, code.IndexOf(":"));
             result[1] = code.Substring(code.IndexOf(":") + 1, code.Length - code.IndexOf(":") - 1);
         }
     }
     return(result);
 }
Beispiel #2
0
        /// <summary>
        /// 替换授权信息
        /// </summary>
        /// <param name="message">传入的请求信息</param>
        /// <param name="userSYS">系统账号用户名明文</param>
        /// <param name="passwordSYS">系统账号密码明文</param>
        /// <returns>替换后的请求信息</returns>
        public static string ReplaceAuthorization(string message, string userSYS, string passwordSYS)
        {
            string result = string.Empty;

            string[] recArray = message.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
            for (int i = 0; i < recArray.Length; i++)
            {
                //授权信息
                if (recArray[i].IndexOf("Authorization") >= 0)
                {
                    recArray[i] = "Authorization: Basic " + Base64Helper.Base64Encode(userSYS + ":" + passwordSYS);
                    break;
                }
            }
            result = string.Join(Environment.NewLine, recArray);
            return(result);
        }