本文整理汇总了C#中System.Text.UTF8Encoding类的典型用法代码示例。如果您正苦于以下问题:C# UTF8Encoding类的具体用法?C# UTF8Encoding怎么用?C# UTF8Encoding使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UTF8Encoding类属于System.Text命名空间,在下文中一共展示了UTF8Encoding类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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(" <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
示例16: EncodeMD5
public static string EncodeMD5(string password)
{
byte[] encodedPassword = new UTF8Encoding().GetBytes(password);
byte[] hash = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(encodedPassword);
string encoded = BitConverter.ToString(hash).Replace("-", string.Empty).ToLower();
return encoded;
}
开发者ID:AdamMalek,项目名称:ProjectTransport,代码行数:7,代码来源:MD5Encoder.cs
示例17: DecodeFromFile
public string DecodeFromFile(string fileName)
{
string keyData = "";
UTF8Encoding utf = new UTF8Encoding();
Rijndael rjn = Rijndael.Create();
Byte[] decIV = { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 };
Byte[] decKey = { 0x3, 0x6, 0x9, 0x12, 0x15, 0x18, 0x21, 0x24, 0x27, 0x30, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF };
rjn.IV = decIV;
rjn.Key = decKey;
ICryptoTransform decoder = rjn.CreateDecryptor(decIV, decKey);
FileStream fOpen = File.Open(fileName, FileMode.OpenOrCreate, FileAccess.Read);
Byte[] encBinData = new Byte[16];
Byte[] decBinData;
int i =0;
for (i = 0; i < fOpen.Length; i += 16)
{
fOpen.Seek((long)i, SeekOrigin.Begin);
fOpen.Read(encBinData, 0, 16);
decBinData = decoder.TransformFinalBlock(encBinData, 0, encBinData.Length);
keyData += utf.GetString(decBinData);
}
fOpen.Close();
return keyData;
}
开发者ID:vipul0092,项目名称:vKeylogger,代码行数:25,代码来源:TextCodec.cs
示例18: GetCriptografiaSimetrica
/// <summary>
/// A chave deve possuir 16 com caracteres "1234567890123456"
/// </summary>
/// <param name="str"></param>
/// <param name="key"></param>
/// <returns></returns>
public static string GetCriptografiaSimetrica(this string str, string key)
{
using (TripleDESCryptoServiceProvider provider = new TripleDESCryptoServiceProvider())
{
provider.Mode = CipherMode.CFB;
provider.Padding = PaddingMode.PKCS7;
MemoryStream mStream = new MemoryStream();
CryptoStream cs = new CryptoStream(mStream, provider.CreateEncryptor(Encoding.UTF8.GetBytes(key), new byte[] { 138, 154, 251, 188, 64, 108, 167, 121 }), CryptoStreamMode.Write);
byte[] toEncrypt = new UTF8Encoding().GetBytes(str);
cs.Write(toEncrypt, 0, toEncrypt.Length);
cs.FlushFinalBlock();
byte[] ret = mStream.ToArray();
mStream.Close();
cs.Close();
str = Convert.ToBase64String(ret);
}
return str;
}
开发者ID:mvasilva,项目名称:MvasilvaFramework,代码行数:34,代码来源:CryptoProvider.cs
示例19: SendSMSAsync
public void SendSMSAsync(Action<bool> callback = null)
{
if (EN_SMS_NT)
{
new Thread(new ThreadStart(() =>
{
try
{
HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create(SMS_URI);
UTF8Encoding encoding = new UTF8Encoding();
byte[] data = encoding.GetBytes(_postData.ToString());
httpWReq.Method = "POST";
httpWReq.ContentType = "application/x-www-form-urlencoded";
httpWReq.ContentLength = data.Length;
using (Stream stream = httpWReq.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string responseString = reader.ReadToEnd();
reader.Close();
response.Close();
if (callback != null) callback(true);
}
catch (SystemException)
{
if (callback != null) callback(false);
}
}))
.Start();
}
}
开发者ID:arunghosh,项目名称:alumni-network,代码行数:34,代码来源:SmsSrv.cs
示例20: OnGUI
//--------------------------------------
// PUBLIC METHODS
//--------------------------------------
void OnGUI()
{
#if (UNITY_IPHONE && !UNITY_EDITOR) || SA_DEBUG_MODE
if(GUI.Button(new Rect(170, 70, 150, 50), "Find Match")) {
GameCenterMultiplayer.instance.FindMatch (2, 2);
}
if(GUI.Button(new Rect(170, 130, 150, 50), "Send Data to All")) {
string msg = "hello world";
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
byte[] data = encoding.GetBytes(msg);
GameCenterMultiplayer.instance.SendDataToAll (data, GameCenterDataSendType.RELIABLE);
}
if(GUI.Button(new Rect(170, 190, 150, 50), "Send to Player")) {
string msg = "hello world";
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
byte[] data = encoding.GetBytes(msg);
GameCenterMultiplayer.instance.sendDataToPlayers (data, GameCenterDataSendType.RELIABLE, GameCenterMultiplayer.instance.match.playerIDs[0]);
}
if(GUI.Button(new Rect(170, 250, 150, 50), "Disconnect")) {
GameCenterMultiplayer.instance.disconnect ();
}
#endif
//turn based
/* if(GUI.Button(new Rect(330, 70, 150, 50), "Trun Based Match")) {
GameCenterMultiplayer.instance.FindTurnBasedMatch (2, 2);
} */
}
开发者ID:nickmudry,项目名称:Lost-In-Space,代码行数:36,代码来源:MultiplayerManagerExample.cs
注:本文中的System.Text.UTF8Encoding类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论