当前位置: 首页>>代码示例>>C#>>正文


C# Text.UTF8Encoding类代码示例

本文整理汇总了C#中System.Text.UTF8Encoding的典型用法代码示例。如果您正苦于以下问题:C# UTF8Encoding类的具体用法?C# UTF8Encoding怎么用?C# UTF8Encoding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UTF8Encoding类属于System.Text命名空间,在下文中一共展示了UTF8Encoding类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetSha1Hash

 public static string GetSha1Hash(this string value)
 {
     var encoding = new UTF8Encoding();
     var hash = new System.Security.Cryptography.SHA1CryptoServiceProvider();
     var hashed = hash.ComputeHash(encoding.GetBytes(value));
     return encoding.GetString(hashed);
 }
开发者ID:MrHayato,项目名称:PhotoCache,代码行数:7,代码来源:StringExtensions.cs

示例2: Encode

        protected string Encode(string value)
        {
            UTF8Encoding encoding = new UTF8Encoding();

            switch (_DataType.Encoding)
            {
                case "BASE64": return Convert.ToBase64String(encoding.GetBytes(value));
                case "7BIT":
                case "8BIT":                
                    value = Regex.Replace(value, @"[^\r]\n", "\r\n");
                    value = Regex.Replace(value, @"\r[^\n]", "\r\n");

                    bool is7Bit = _DataType.Encoding.Equals("7BIT");

                    List<byte> data = new List<byte>(encoding.GetBytes(value));
                    for (int i = data.Count - 1; i >= 0; i--)
                    {
                        if (data[i] == 0)
                            data.RemoveAt(i);

                        if (is7Bit && data[i] > 127)
                            data.RemoveAt(i);
                    }

                    return encoding.GetString(data.ToArray());
                default:
                    return value;
            }
        }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:29,代码来源:EncodableDataTypeSerializer.cs

示例3: EncryptionHelper

 // Methods
 public EncryptionHelper()
 {
     RijndaelManaged managed = new RijndaelManaged();
     this.EncryptorTransform = managed.CreateEncryptor(this.Key, this.Vector);
     this.DecryptorTransform = managed.CreateDecryptor(this.Key, this.Vector);
     this.UTFEncoder = new UTF8Encoding();
 }
开发者ID:Alchemy86,项目名称:DAS-Desktop,代码行数:8,代码来源:EncryptionHelper.cs

示例4: AesEncryption

 public AesEncryption(byte[] Key, byte[] Vector)
 {
     RijndaelManaged rijndaelManaged = new RijndaelManaged();
     this.EncryptorTransform = rijndaelManaged.CreateEncryptor(Key, Vector);
     this.DecryptorTransform = rijndaelManaged.CreateDecryptor(Key, Vector);
     this.UTFEncoder = new UTF8Encoding();
 }
开发者ID:PrivateOrganizationC,项目名称:Primary,代码行数:7,代码来源:AesEncryption.cs

示例5: MD5

 public static String MD5(String text)
 {
     UTF8Encoding encoder = new UTF8Encoding();
     var md5 = new MD5CryptoServiceProvider();
     byte[] hashedDataBytes = md5.ComputeHash(encoder.GetBytes(text));
     return System.Convert.ToBase64String(hashedDataBytes);
 }
开发者ID:codaxy,项目名称:common,代码行数:7,代码来源:Cryptography.cs

示例6: Process

        private static void Process(Object param)
        {
            HttpListenerContext context = (HttpListenerContext)param;
            Encoding encoder = new UTF8Encoding();

            string url = context.Request.Url.AbsolutePath;

            Match url_match = Regex.Match(url, SearchUrlMatcher);
            if (!url_match.Success)
            {
                Form1.LogInfo("Unknown URL: " + url);
                return;
            }
            String AlbumName = HttpUtility.UrlDecode(url_match.Groups["Album"].ToString());
            String ArtistName = HttpUtility.UrlDecode(url_match.Groups["Artist"].ToString());

            AlbumArtRetriever retriever = AlbumArtRetrieverManager.getSelectedRetriever();

            int album_count = 0;
            String result_line = "";
            foreach (AlbumInfo album in retriever.retrieve(ArtistName, AlbumName))
            {
                album_count++;
                result_line += String.Format(PicRegexGenerator, album.AlbumArtURL, album.AlbumName, album.Artist);
            }
            Match m = Regex.Match(result_line, PicRegex);
            String s = m.Groups["Artist"].Value;
            byte[] result_bytes = encoder.GetBytes(result_line);
            context.Response.OutputStream.Write(result_bytes, 0, result_bytes.Length);
            Form1.LogInfo(String.Format("Search of {0} {1} via {2} returned {3} albums.",
                new object[] {ArtistName, AlbumName, retriever.getName(), album_count}));

            context.Response.OutputStream.Close();
        }
开发者ID:xurubin,项目名称:MXiTunesHelper,代码行数:34,代码来源:AlbumArtServer.cs

示例7: Base64Decode

        /// <summary>
        /// Base64 Decode
        /// </summary>
        /// <param name="src"></param>
        /// <returns></returns>
        public static string Base64Decode(string src)
        {
            string sReturn = "";

            if (src != "")
            {
                byte[] arr = null;
                UTF8Encoding uniEnc = null;

                try
                {
                    uniEnc = new UTF8Encoding();
                    arr = Convert.FromBase64String(src);
                    sReturn = uniEnc.GetString(arr);
                }
                catch
                {
                }
                finally
                {
                    uniEnc = null;
                }
            }
            return sReturn;
        }
开发者ID:sunyruru,项目名称:ruru-library,代码行数:30,代码来源:Base64Convert.cs

示例8: SendRequest

        /// <summary>
        /// Sends some data to a URL using an HTTP POST.
        /// </summary>
        /// <param name="url">Url to send to</param>
        /// <param name="postData">The data to send</param>
        public string SendRequest(string url, string postData)
        {
            var uri = new Uri(url);
            var request = WebRequest.Create(uri);
            var encoding = new UTF8Encoding();
            var requestData = encoding.GetBytes(postData);

            request.ContentType = "application/x-www-form-urlencoded";
            request.Method = "POST";
            request.Timeout = (300 * 1000); //TODO: Move timeout to config
            request.ContentLength = requestData.Length;

            using (var stream = request.GetRequestStream())
            {
                stream.Write(requestData, 0, requestData.Length);
            }

            var response = request.GetResponse();

            string result;

            using (var reader = new StreamReader(response.GetResponseStream(), Encoding.ASCII))
            {
                result = reader.ReadToEnd();
            }

            return result;
        }
开发者ID:neozhu,项目名称:Ecommerce,代码行数:33,代码来源:HttpRequestSender.cs

示例9: RijndaelHelper

 public RijndaelHelper(byte[] key, byte[] vector)
 {
     encoding = new UTF8Encoding();
     rijndael = Rijndael.Create();
     rijndael.Key = key;
     rijndael.IV = vector;
 }
开发者ID:buddhika85,项目名称:Stage7_UserLogin,代码行数:7,代码来源:RijndaelHelper.cs

示例10: Parse

        public static NameValueCollection Parse(Stream stream)
        {
            Dictionary<string, string[]> form = new Dictionary<string, string[]>();
            UTF8Encoding encoding = new UTF8Encoding(false);

            return HttpUtility.ParseQueryString(encoding.GetString(stream.ReadAllBytes()),encoding);
        }
开发者ID:sgarver,项目名称:RadMVC,代码行数:7,代码来源:FormParser.cs

示例11: AuthenticationHelper

 public AuthenticationHelper()
 {
     var rm = new RijndaelManaged();
     encryptor = rm.CreateEncryptor(key, vector);
     decryptor = rm.CreateDecryptor(key, vector);
     encoder = new UTF8Encoding();
 }
开发者ID:mattycare,项目名称:ReVersion,代码行数:7,代码来源:AuthenticationHelper.cs

示例12: ComputeHash

        public string ComputeHash(string data)
        {
            var bytes = new UTF8Encoding().GetBytes(data);
            var hash = _hashAlgorithm.ComputeHash(bytes);

            return Convert.ToBase64String(hash);
        }
开发者ID:rubenlr,项目名称:Utilities,代码行数:7,代码来源:Hashing.cs

示例13: LogUser

        public String LogUser( LogInfo info )
        {
            HttpWebRequest request = bnRequest(@"https://www.battlenet.com.cn/login/zh/");
            request.CookieContainer = cc;

            request.Method = WebRequestMethods.Http.Post;
            request.ContentType = "application/x-www-form-urlencoded";

            String postString = "";
            postString += "accountName=" + Uri.EscapeUriString(info.UserMail);
            postString += "&password=" + Uri.EscapeUriString(info.PassWord);
            if (info.NeedVerify) {
                throw new NotImplementedException("verify");
            }

            byte[] postData = new UTF8Encoding().GetBytes(postString);
            request.ContentLength = postData.Length;
            Stream postStream = request.GetRequestStream();
            postStream.Write(postData, 0, postData.Length);
            postStream.Close();

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream dataStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(dataStream);
            return  reader.ReadToEnd();
        }
开发者ID:srayuws,项目名称:wowAHwatcher,代码行数:26,代码来源:bnWebProxy.cs

示例14: GetConvertion

        public decimal GetConvertion(string from, string to)
        {
            WebClient objWebClient = null;
            UTF8Encoding objUTF8 = null;
            decimal result = 0;

            try{
                objWebClient = new WebClient();
                objUTF8 = new UTF8Encoding();

                byte[] aRequestedHTML = objWebClient.DownloadData(String.Format("http://www.xe.com/ucc/convert/?Amount=1&From={0}&To={1}", from, to));
                string strRequestedHTML = objUTF8.GetString(aRequestedHTML);

                int search1 = strRequestedHTML.LastIndexOf("&nbsp;<span class=\"uccResCde\">USD</span>");
                string search2 = strRequestedHTML.Substring(search1 - 21, 21);
                int search3 = search2.LastIndexOf(">");
                string stringRepresentingCE = search2.Substring(search3 + 1);

                result = Convert.ToDecimal(stringRepresentingCE.Trim());

            }
            catch (Exception ex){
                // Agregar codigo para manejar la excepción.
            }

            return result;
        }
开发者ID:nalia2015,项目名称:tusegurodeviaje1,代码行数:27,代码来源:conversiondemonedas.cs

示例15: RequestGetToUrl

        private static string RequestGetToUrl(string url)
        {
            WebProxy proxy = WebProxy.GetDefaultProxy();
            if (string.IsNullOrEmpty(url))
                return null;

            if (url.IndexOf("://") <= 0)
                url = "http://" + url.Replace(",", ".");

            try
            {
                using (var client = new WebClient())
                {
                    //proxy
                    if (proxy != null)
                        client.Proxy = proxy;

                    //response
                    byte[] response = client.DownloadData(url);
                    //out
                    var enc = new UTF8Encoding();
                    string outp = enc.GetString(response);
                    return outp;
                }
            }
            catch (WebException ex)
            {
                string err = ex.Message;
            }
            catch (Exception ex)
            {
                string err = ex.Message;
            }
            return null;
        }
开发者ID:msx752,项目名称:OPALOP-Picture-Mosaic,代码行数:35,代码来源:InstagramProfile.cs


注:本文中的System.Text.UTF8Encoding类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。