本文整理汇总了C#中System.Text.ASCIIEncoding.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# System.Text.ASCIIEncoding.GetBytes方法的具体用法?C# System.Text.ASCIIEncoding.GetBytes怎么用?C# System.Text.ASCIIEncoding.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.ASCIIEncoding
的用法示例。
在下文中一共展示了System.Text.ASCIIEncoding.GetBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCurrentAirInstall
public string GetCurrentAirInstall(string Location)
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
DirectoryInfo dInfo = new DirectoryInfo(Location);
DirectoryInfo[] subdirs = null;
try
{
subdirs = dInfo.GetDirectories();
}
catch { return "0.0.0.0"; }
string latestVersion = "0.0.1";
foreach (DirectoryInfo info in subdirs)
{
latestVersion = info.Name;
}
string AirLocation = Path.Combine(Location, latestVersion, "deploy");
if (!File.Exists(Path.Combine(Client.ExecutingDirectory, "ClientLibCommon.dat")))
{
File.Copy(Path.Combine(AirLocation, "lib", "ClientLibCommon.dat"), Path.Combine(Client.ExecutingDirectory, "ClientLibCommon.dat"));
}
if (!File.Exists(Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite")))
{
File.Copy(Path.Combine(AirLocation, "assets", "data", "gameStats", "gameStats_en_US.sqlite"), Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite"));
}
Copy(Path.Combine(AirLocation, "assets", "images", "abilities"), Path.Combine(Client.ExecutingDirectory, "Assets", "abilities"));
Copy(Path.Combine(AirLocation, "assets", "images", "champions"), Path.Combine(Client.ExecutingDirectory, "Assets", "champions"));
var VersionAIR = File.Create(Path.Combine("Assets", "VERSION_AIR"));
VersionAIR.Write(encoding.GetBytes(latestVersion), 0, encoding.GetBytes(latestVersion).Length);
VersionAIR.Close();
return latestVersion;
}
示例2: Encrypt
/// <summary>
/// 指定されたUIDを暗号化して返します。
/// </summary>
/// <param name="uid">MUID</param>
/// <returns></returns>
public static string Encrypt(string uid)
{
var encryptStr = "";
if (!string.IsNullOrEmpty(uid))
{
if (CheckMuid(uid))
{
uid = uid.Replace(".", "");
if(uid.Length%2!=0)
{
uid = uid + "0";
}
var asciiEncoding = new System.Text.ASCIIEncoding();
for (int i = 0; i < uid.Length / 2; i++)
{
var subUid = uid.Substring(i * 2, 2);
encryptStr = encryptStr + subUid + ((asciiEncoding.GetBytes(uid.Substring(i * 2, 1))[0] + asciiEncoding.GetBytes(uid.Substring(i * 2 + 1, 1))[0]) % 15).ToString("x");
}
char[] arr = encryptStr.ToCharArray();
Array.Reverse(arr);
encryptStr = new string(arr);
}
else
{
encryptStr = "00000";
}
}
else
{
encryptStr = "00000";
}
return encryptStr;
}
示例3: GetCurrentGameInstall
public string GetCurrentGameInstall(string GameLocation)
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
DirectoryInfo dInfo = new DirectoryInfo(Path.Combine(GameLocation, "projects", "lol_game_client", "filearchives"));
DirectoryInfo[] subdirs = null;
try
{
subdirs = dInfo.GetDirectories();
}
catch { return "0.0.0.0"; }
string latestVersion = "0.0.1";
foreach (DirectoryInfo info in subdirs)
{
latestVersion = info.Name;
}
string ParentDirectory = Directory.GetParent(GameLocation).FullName;
Copy(Path.Combine(ParentDirectory, "Config"), Path.Combine(Client.ExecutingDirectory, "Config"));
Copy(Path.Combine(GameLocation, "projects", "lol_game_client"), Path.Combine(Client.ExecutingDirectory, "RADS", "projects", "lol_game_client"));
File.Copy(Path.Combine(GameLocation, "RiotRadsIO.dll"), Path.Combine(Client.ExecutingDirectory, "RADS", "RiotRadsIO.dll"));
var VersionAIR = File.Create(Path.Combine("RADS", "VERSION_LOL"));
VersionAIR.Write(encoding.GetBytes(latestVersion), 0, encoding.GetBytes(latestVersion).Length);
VersionAIR.Close();
return latestVersion;
}
示例4: CreateToken
private static string CreateToken(string message, string secret)
{
// don't allow null secrets
secret = secret ?? "";
var encoding = new System.Text.ASCIIEncoding();
byte[] keyByte = encoding.GetBytes(secret);
byte[] messageBytes = encoding.GetBytes(message);
using (var hmacsha256 = new System.Security.Cryptography.HMACSHA256(keyByte))
{
byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
return Convert.ToBase64String(hashmessage);
}
}
示例5: EncryptPassword
public static string EncryptPassword(string password)
{
string secret = "";
var encoding = new System.Text.ASCIIEncoding();
byte[] keyByte = encoding.GetBytes(secret);
byte[] messageBytes = encoding.GetBytes(password);
string pwdEncript = "";
using (var hmacsha256 = new HMACSHA256(keyByte))
{
byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
pwdEncript = Convert.ToBase64String(hashmessage);
}
return pwdEncript;
}
示例6: GenerateSignature
private string GenerateSignature(IRestClient client, IRestRequest request)
{
var uri = client.BuildUri(request);
var query = uri.Query;
if (!string.IsNullOrEmpty(query))
query = query.Substring(1);
var encoding = new System.Text.ASCIIEncoding();
var key = encoding.GetBytes(_apiKey);
var myhmacsha256 = new HMACSHA256(key);
var hashValue = myhmacsha256.ComputeHash(encoding.GetBytes(query));
var hmac64 = Convert.ToBase64String(hashValue);
return hmac64;
}
示例7: CutString
/// <summary>
/// 截取指定长度字符串,汉字为2个字符
/// </summary>
/// <param name="inputString">要截取的目标字符串</param>
/// <param name="len">截取长度</param>
/// <returns>截取后的字符串</returns>
public static string CutString(string inputString, int len)
{
System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();
int tempLen = 0;
string tempString = "";
byte[] s = ascii.GetBytes(inputString);
for (int i = 0; i < s.Length; i++)
{
if ((int)s[i] == 63)
tempLen += 2;
else
tempLen += 1;
try
{
tempString += inputString.Substring(i, 1);
}
catch
{
break;
}
if (tempLen > len)
break;
}
return tempString;
}
示例8: sendmessage
public static bool sendmessage(MessageTypes type, string msg, ref byte[] data)
{
try
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] message = encoding.GetBytes(msg);
int size = HEADERSIZE + message.Length;
data = new byte[size];
byte[] sizebyte = BitConverter.GetBytes(size);
byte[] typebyte = BitConverter.GetBytes((int)type);
Array.Copy(sizebyte, 0, data, LENGTHOFFSET, sizebyte.Length);
Array.Copy(typebyte, 0, data, TYPEOFFSET, typebyte.Length);
Array.Copy(message, 0, data, HEADERSIZE, message.Length);
}
#if DEBUG
catch (Exception ex)
{
Console.WriteLine("error processing: " + type.ToString() + " msg: " + msg + " err: " + ex.Message + ex.StackTrace);
return false;
}
#else
catch (Exception)
{
}
#endif
return true;
}
示例9: Post
public string Post(Uri uri, NameValueCollection input)
{
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
WebRequest request = WebRequest.Create(uri);
string strInput = GetInputString(input);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = strInput.Length;
Stream writeStream = request.GetRequestStream();
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] bytes = encoding.GetBytes(strInput);
writeStream.Write(bytes, 0, bytes.Length);
writeStream.Close();
using (WebResponse response = request.GetResponse())
{
using (Stream responseStream = response.GetResponseStream())
{
StreamReader streamReader = new StreamReader(responseStream);
return streamReader.ReadToEnd();
}
}
}
示例10: CheckMuid
/// <summary>
/// Uidチェック(0~9|a~z|A~Z)かつ18桁
/// </summary>
/// <param name="uid">UID</param>
/// <returns></returns>
private static bool CheckMuid(string uid)
{
var asciiEncoding = new System.Text.ASCIIEncoding();
var rst = uid.Select((t, i) => (int)asciiEncoding.GetBytes(uid.Substring(i, 1))[0]).Aggregate(true, (current, z) => current && ((47 < z && z < 58) || (64 < z && z < 91) || (96 < z && z < 123) || z==46));
return rst;
}
示例11: Main
static void Main(string[] args)
{
/*
* Make sure this path contains the umundoNativeCSharp.dll!
*/
SetDllDirectory("C:\\Users\\sradomski\\Desktop\\build\\umundo\\lib");
org.umundo.core.Node node = new org.umundo.core.Node();
Publisher pub = new Publisher("pingpong");
PingReceiver recv = new PingReceiver();
Subscriber sub = new Subscriber("pingpong", recv);
node.addPublisher(pub);
node.addSubscriber(sub);
while (true)
{
Message msg = new Message();
String data = "data";
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
byte[] buffer = enc.GetBytes(data);
msg.setData(buffer);
msg.putMeta("foo", "bar");
Console.Write("o");
pub.send(msg);
System.Threading.Thread.Sleep(1000);
}
}
示例12: GetAuthorizationToken
/// <summary>
/// Function for getting a token from ACS using Application Service principal Id and Password.
/// </summary>
public static AADJWTToken GetAuthorizationToken(string tenantName, string appPrincipalId, string password)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(String.Format(StringConstants.AzureADSTSURL, tenantName));
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
string postData = "grant_type=client_credentials";
postData += "&resource=" + HttpUtility.UrlEncode(StringConstants.GraphPrincipalId);
postData += "&client_id=" + HttpUtility.UrlEncode(appPrincipalId);
postData += "&client_secret=" + HttpUtility.UrlEncode(password);
byte[] data = encoding.GetBytes(postData);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
using (Stream stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
using (var response = request.GetResponse())
{
using (var stream = response.GetResponseStream())
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(AADJWTToken));
AADJWTToken token = (AADJWTToken)(ser.ReadObject(stream));
return token;
}
}
}
开发者ID:michaelsrichter,项目名称:AccidentalFish.AspNet.Identity.Azure,代码行数:30,代码来源:DirectoryDataServiceAuthorizationHelper.cs
示例13: Encode
public static string Encode(string value)
{
var hash = System.Security.Cryptography.SHA1.Create();
var encoder = new System.Text.ASCIIEncoding();
var combined = encoder.GetBytes(value ?? "");
return BitConverter.ToString(hash.ComputeHash(combined)).ToLower().Replace("-", "");
}
示例14: StringToByteArray
/// <summary>
/// Convert string to a byte array.
/// </summary>
/// <param name="text">String to convert.</param>
/// <returns>Byte array. null if text is null, and empty array if
/// the string is empty.
///</returns>
public static byte[] StringToByteArray(string text)
{
if (text == null)
return null;
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
return encoding.GetBytes(text);
}
示例15: WriteData
private void WriteData(Stream requestStream, string data)
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] dataAsBytes = encoding.GetBytes(data);
Stream dataStream = requestStream;
dataStream.Write(dataAsBytes, 0, dataAsBytes.Length);
dataStream.Close();
}