本文整理汇总了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);
}
示例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;
}
}
示例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();
}
示例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();
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例9: RijndaelHelper
public RijndaelHelper(byte[] key, byte[] vector)
{
encoding = new UTF8Encoding();
rijndael = Rijndael.Create();
rijndael.Key = key;
rijndael.IV = vector;
}
示例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);
}
示例11: AuthenticationHelper
public AuthenticationHelper()
{
var rm = new RijndaelManaged();
encryptor = rm.CreateEncryptor(key, vector);
decryptor = rm.CreateDecryptor(key, vector);
encoder = new UTF8Encoding();
}
示例12: ComputeHash
public string ComputeHash(string data)
{
var bytes = new UTF8Encoding().GetBytes(data);
var hash = _hashAlgorithm.ComputeHash(bytes);
return Convert.ToBase64String(hash);
}
示例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();
}
示例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(" <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;
}
示例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;
}