本文整理汇总了C#中System.Text.ASCIIEncoding.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# ASCIIEncoding.GetBytes方法的具体用法?C# ASCIIEncoding.GetBytes怎么用?C# ASCIIEncoding.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.ASCIIEncoding
的用法示例。
在下文中一共展示了ASCIIEncoding.GetBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DecryptFileString
public bool DecryptFileString(string aPublicKey, string aIV, string aFileName)
{
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] bytes = encoding.GetBytes(aPublicKey);
byte[] buffer2 = encoding.GetBytes(aIV);
return this.DecryptFile(bytes, buffer2, aFileName);
}
示例2: TestMethodReceivePrivateMessage
public void TestMethodReceivePrivateMessage()
{
ASCIIEncoding encoding = new ASCIIEncoding();
DSACryptoServiceProvider mycryptoC = new DSACryptoServiceProvider();
DSAParameters publickeyC = mycryptoC.ExportParameters(false);
DSACryptoServiceProvider mycryptoW = new DSACryptoServiceProvider();
DSAParameters publickeyW = mycryptoW.ExportParameters(false);
byte[] hashC = mycryptoC.SignData(encoding.GetBytes("Cuddy"));
byte[] hashW = mycryptoW.SignData(encoding.GetBytes("Wilson"));
ServiceReference1.ServeurChatSoapClient a = new ServiceReference1.ServeurChatSoapClient();
a.Register("Cuddy", "iluvhouse", hashC, publickeyC.Counter, publickeyC.G, publickeyC.J, publickeyC.P, publickeyC.Q, publickeyC.Seed, publickeyC.X, publickeyC.Y);
a.Register("Wilson", "ihatehouse", hashW, publickeyW.Counter, publickeyW.G, publickeyW.J, publickeyW.P, publickeyW.Q, publickeyW.Seed, publickeyW.X, publickeyW.Y);
string message = "je suis jalouse de Cameron";
byte[] messagesigned = mycryptoC.SignData(encoding.GetBytes(message));
a.SendPrivateMessage("Cuddy", "Wilson", message, messagesigned);
UnitTest.ServiceReference1.Message[] b = a.ReceivePrivateMessage("Wilson", hashW);
Assert.AreEqual("Cuddy", b[0].Auteur); //j'avoue les test sont moisi... mais je voulais juste verifier si le retour par une classe implemente dans le webservice etait possible
Assert.AreEqual("je suis jalouse de Cameron", b[0].Text);
File.Delete("C:\\Program Files\\Common Files\\microsoft shared\\DevServer\\10.0\\Message_serialization.xml");
File.Delete("C:\\Program Files\\Common Files\\microsoft shared\\DevServer\\10.0\\User_serialization.xml");
}
示例3: EncryptPwd
//1 先sha1加密成36位,
//2 移除前后2位,使之变成一个32位数(看起来像一个MD5的加密值)
//3 再将结果MD5一次
public static string EncryptPwd(string pwd)
{
if (string.IsNullOrWhiteSpace(pwd))
throw new ArgumentNullException(pwd, "密码不能为空");
//建立SHA1对象
SHA1 sha = new SHA1CryptoServiceProvider();
//将mystr转换成byte[]
ASCIIEncoding enc = new ASCIIEncoding();
byte[] dataToHash = enc.GetBytes(pwd);
//Hash运算
byte[] dataHashed = sha.ComputeHash(dataToHash);
string hash = BitConverter.ToString(dataHashed).Replace("-", "");
//移除前后2位
hash = hash.Substring(2).Substring(0, hash.Length - 2);
//md5加密
dataToHash = enc.GetBytes(hash);
MD5 md5 = new MD5CryptoServiceProvider();
dataHashed = md5.ComputeHash(dataToHash);
hash = BitConverter.ToString(dataHashed).Replace("-", "");
return hash;
}
示例4: sendContribution
/// <summary>
///
/// </summary>
/// <param name="pData"></param>
/// <returns></returns>
public bool sendContribution(String pData)
{
bool lRetVal = false;
HttpWebRequest httpWReq = (HttpWebRequest)WebRequest.Create("http://buglist.io/c/contribute.php");
ASCIIEncoding encoding = new ASCIIEncoding();
String lUserAgent = String.Format("Mozilla/4.0 (compatible; MSIE 10.0; Windows NT 6.4; .NET CLR 4.1234)");
try
{
byte[] data = encoding.GetBytes(pData);
String lEncodedData = String.Format("data={0}", System.Web.HttpUtility.UrlEncode(data));
httpWReq.Method = "POST";
httpWReq.ContentType = "application/x-www-form-urlencoded";
httpWReq.ContentLength = lEncodedData.Length;
httpWReq.UserAgent = lUserAgent;
using (Stream stream = httpWReq.GetRequestStream())
{
stream.Write(encoding.GetBytes(lEncodedData), 0, lEncodedData.Length);
}
HttpWebResponse response = (HttpWebResponse)httpWReq.GetResponse();
String responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
LogConsole.Main.LogConsole.pushMsg(String.Format("Contribution sent ({0}) : {1}", getMethod(), String.Format("{0} ...", lEncodedData.Substring(0, 30))));
lRetVal = true;
}
catch (Exception lEx)
{
LogConsole.Main.LogConsole.pushMsg("Error sending contribution message : " + lEx.Message);
}
return (lRetVal);
}
示例5: TestMethodSendPrivateMessage
public void TestMethodSendPrivateMessage()
{
ASCIIEncoding encoding = new ASCIIEncoding();
DSACryptoServiceProvider mycryptoC = new DSACryptoServiceProvider();
DSAParameters publickeyC = mycryptoC.ExportParameters(false);
DSACryptoServiceProvider mycryptoW = new DSACryptoServiceProvider();
DSAParameters publickeyW = mycryptoW.ExportParameters(false);
byte[] hashC = mycryptoC.SignData(encoding.GetBytes("Cuddy"));
byte[] hashW = mycryptoW.SignData(encoding.GetBytes("Wilson"));
ServiceReference1.ServeurChatSoapClient a = new ServiceReference1.ServeurChatSoapClient();
a.Register("Cuddy", "iluvhouse", hashC, publickeyC.Counter, publickeyC.G, publickeyC.J, publickeyC.P, publickeyC.Q, publickeyC.Seed, publickeyC.X, publickeyC.Y);
a.Register("Wilson", "ihatehouse", hashW, publickeyW.Counter, publickeyW.G, publickeyW.J, publickeyW.P, publickeyW.Q, publickeyW.Seed, publickeyW.X, publickeyW.Y);
string message = "je suis jalouse de Cameron";
byte[] messagesigned = mycryptoC.SignData(encoding.GetBytes(message));
Assert.AreEqual(true,a.SendPrivateMessage("Cuddy", "Wilson", message, messagesigned));
Assert.AreEqual(false, a.SendPrivateMessage("Cuddy", "Foreman", message, messagesigned));
File.Delete("C:\\Program Files\\Common Files\\microsoft shared\\DevServer\\10.0\\Message_serialization.xml");
File.Delete("C:\\Program Files\\Common Files\\microsoft shared\\DevServer\\10.0\\User_serialization.xml");
}
示例6: Main
static void Main(string[] args)
{
int _arg1 = 9;
char[] _arg2 = new char[8]{'a','s','d','f','a','s','d','\0'};
int _arg3 = 1;
int _arg4 = 2;
char[] _arg5 = new char[32]{
'0','0','0','0','0','0','0','0',
'0','0','0','0','0','0','0','0',
'0','0','0','0','0','0','0','0',
'0','0','0','0','0','0','0','0'
};
char[] _arg6 = new char[32]{
'0','0','0','0','0','0','0','0',
'0','0','0','0','0','0','0','0',
'0','0','0','0','0','0','0','0',
'0','0','0','0','0','0','0','0'
};
char[] _arg7 = new char[9]{
't','u','r','n','r','i','g','h','t'
};
byte[] arg1 = new byte[4];
byte[] arg2 = new byte[8];
byte[] arg3 = new byte[4];
byte[] arg4 = new byte[4];
byte[] arg5 = new byte[32];
byte[] arg6 = new byte[32];
byte[] arg7 = new byte[9];
// encode
ASCIIEncoding encoding = new ASCIIEncoding();
arg1 = BitConverter.GetBytes(_arg1);
arg2 = encoding.GetBytes(_arg2);
arg3 = BitConverter.GetBytes(_arg3);
arg4 = BitConverter.GetBytes(_arg4);
arg5 = encoding.GetBytes(_arg5);
arg6 = encoding.GetBytes(_arg6);
arg7 = encoding.GetBytes(_arg7);
int offset = 0;
Buffer.BlockCopy(arg1, 0, rawdata, offset, arg1.Length); offset += arg1.Length;
Buffer.BlockCopy(arg2, 0, rawdata, offset, arg2.Length); offset += arg2.Length;
Buffer.BlockCopy(arg3, 0, rawdata, offset, arg3.Length); offset += arg3.Length;
Buffer.BlockCopy(arg4, 0, rawdata, offset, arg4.Length); offset += arg4.Length;
Buffer.BlockCopy(arg5, 0, rawdata, offset, arg5.Length); offset += arg5.Length;
Buffer.BlockCopy(arg6, 0, rawdata, offset, arg6.Length); offset += arg6.Length;
Buffer.BlockCopy(arg7, 0, rawdata, offset, arg7.Length); offset += arg7.Length;
// 이 시점에서 rawdata를 전송받았다고 생각합시다.
// decode
offset = 0;
int streamSize = BitConverter.ToInt32(rawdata, offset);
Console.WriteLine(streamSize); offset += 4;
Console.WriteLine(Encoding.Default.GetString(rawdata, offset, 8)); offset += 8;
Console.WriteLine(BitConverter.ToInt32(rawdata, offset)); offset += 4;
Console.WriteLine(BitConverter.ToInt32(rawdata, offset)); offset += 4 + 64;
Console.WriteLine(Encoding.Default.GetString(rawdata, offset, streamSize));
}
示例7: Encode
public static string Encode(string key, string value)
{
var encoding = new ASCIIEncoding();
var hmacsha1 = new HMACSHA1(encoding.GetBytes(key));
var hashValue = hmacsha1.ComputeHash(encoding.GetBytes(value));
return CryptographyHelper.ByteToString(hashValue);
}
示例8: Print
public void Print(string driverName, string name, string userID, string userPicture, bool admin, out string msg)
{
int error;
ZBRGraphics graphics = null;
ASCIIEncoding ascii;
msg = "";
try {
int fontStyle = BOLD;
graphics = new ZBRGraphics();
ascii = new ASCIIEncoding();
//Initialize Graphics
if (graphics.InitGraphics(ascii.GetBytes(driverName), out error) == 0) {
msg = "InitGraphics method error code: " + error.ToString();
return;
}
//DrawImage(location of image, X coordinate, Y coordinate, length, width, out error)
if (admin == false){ //Does the user have admin? No
if (graphics.DrawImage(ascii.GetBytes(Application.StartupPath + "\\Student.png"), 350, 30, 400, 50, out error) == 0) {
msg = "DrawImage method error code: " + error.ToString();
return;
}
} else { //They do have admin
if (graphics.DrawImage(ascii.GetBytes(Application.StartupPath + "\\Admin.png"), 350, 30, 400, 50, out error) == 0) {
msg = "DrawImage method error code: " + error.ToString();
return;
}
}
//DrawImage(location of image, X coordinate, Y coordinate, length, width, out error)
if (graphics.DrawImage(ascii.GetBytes(userPicture), 30, 30, 200, 150, out error) == 0) {
msg = "DrawImage method error code: " + error.ToString();
return;
}
//DrawText(X Coordinate, Y Coordinate, String, Font type, font size, fontStyle, color, out error)
if (graphics.DrawText(35, 575, ascii.GetBytes(name), ascii.GetBytes("Arial"), 12, fontStyle, 0xFF0000, out error) == 0){
msg = "DrawText method error code: " + error.ToString();
return;
}
//DrawBarcode(X Coordinate, Y Coordinate, rotation, barcode type, width ratio, multiplier, height, text under, barcode data, out error)
if (graphics.DrawBarcode(35, 500, 0, 0, 3, 6, 90, 0, ascii.GetBytes(userID), out error) == 0){
msg = "DrawBarcode method error code: " + error.ToString();
return;
}
if (graphics.PrintGraphics(out error) == 0) {
msg = "PrintGraphics Error: " + error.ToString();
return;
}
} catch (Exception e) {
MessageBox.Show(e.ToString());
} finally {
ascii = null;
if (graphics != null) {
if (graphics.CloseGraphics(out error) == 0) {
msg = "CloseGraphics method error code: " + error.ToString();
}
graphics = null;
}
}
}
示例9: OutputAsBytes
internal byte[] OutputAsBytes()
{
// Experimental
MemoryStream ms = new MemoryStream();
BinaryWriter bw = new BinaryWriter(ms, new ASCIIEncoding());
bw.Write((int)0);
bw.Write(RequestId);
bw.Write((int)ServerDataSent);
bw.Write(String1);
bw.Write(String2);
// End
byte[] packetsize;
byte[] req_id;
byte[] serverdata;
byte[] bstring1;
byte[] bstring2;
ASCIIEncoding Ascii = new ASCIIEncoding();
bstring1 = Ascii.GetBytes(String1);
bstring2 = Ascii.GetBytes(String2);
serverdata = BitConverter.GetBytes((int)ServerDataSent);
req_id = BitConverter.GetBytes(RequestId);
// Compose into one packet.
byte[] FinalPacket = new byte[4 + 4 + 4 + bstring1.Length + 1 + bstring2.Length + 1];
packetsize = BitConverter.GetBytes(FinalPacket.Length - 4);
int BPtr = 0;
packetsize.CopyTo(FinalPacket, BPtr);
BPtr += 4;
req_id.CopyTo(FinalPacket, BPtr);
BPtr += 4;
serverdata.CopyTo(FinalPacket, BPtr);
BPtr += 4;
bstring1.CopyTo(FinalPacket, BPtr);
BPtr += bstring1.Length;
FinalPacket[BPtr] = (byte)0;
BPtr++;
bstring2.CopyTo(FinalPacket, BPtr);
BPtr += bstring2.Length;
FinalPacket[BPtr] = (byte)0;
BPtr++;
return FinalPacket;
}
示例10: ReceiveCallback
public static void ReceiveCallback(IAsyncResult AsyncCall)
{
allDone.Set();
var DatajsonGuest = new ArduinoSP.DictionaryJson();
{
DatajsonGuest.temperDS18b20 = Form1.mas[2];
DatajsonGuest.pressureBMP085 = Form1.mas[3];
DatajsonGuest.temperBMP085 = Form1.mas[4];
DatajsonGuest.humidityDHT22 = Form1.mas[5];
DatajsonGuest.temperDHT22 = Form1.mas[6];
}
var jsondat = JsonConvert.SerializeObject(DatajsonGuest);
//SocketAsyncEventArgs e = new SocketAsyncEventArgs();
int i = 0;
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
Socket listener = (Socket)AsyncCall.AsyncState;
Socket client = listener.EndAccept(AsyncCall);
try{
while (true)
{
i = client.Receive(cldata);
Byte[] message = encoding.GetBytes(jsondat);
if (i > 0)
{
data = Encoding.UTF8.GetString(cldata, 0, i);
if (data == "END")
{
Byte[] messagуe = encoding.GetBytes("ClientDisconnekt");
client.Send(messagуe);
client.Close();
break;
}
client.Send(message);
}
}
}
catch (SocketException){
}
catch (Exception) { }
// client.Close();
// После того как завершили соединение, говорим ОС что мы готовы принять новое
// listener.BeginAccept(new AsyncCallback(ReceiveCallback), listener);
}
示例11: GetLatestLCLOLVersion
public string GetLatestLCLOLVersion()
{
if (File.Exists(Path.Combine(Client.ExecutingDirectory, "LC_LOL.Version")))
{
return File.ReadAllText(Path.Combine(Client.ExecutingDirectory, "LC_LOL.Version")).Split( new []{Environment.NewLine}, StringSplitOptions.None)[0];
}
var encoding = new ASCIIEncoding();
File.Create(Path.Combine(Client.ExecutingDirectory, "LC_LOL.Version")).Write(encoding.GetBytes("0.0.0.0"), 0, encoding.GetBytes("0.0.0.0").Length);
return "0.0.0.0";
}
示例12: Sign
internal String Sign(String feedId)
{
Encoding encoding = new ASCIIEncoding();
var hashedSecret = (new SHA1Managed()).ComputeHash(encoding.GetBytes(_apiSecret));
var hmac = new HMACSHA1(hashedSecret);
return Convert.ToBase64String(hmac.ComputeHash(encoding.GetBytes(feedId)))
.Replace('+', '-')
.Replace('/', '_')
.Trim('=');
}
示例13: BuildKey
public void BuildKey(string newkey)
{
int start = 0;
ASCIIEncoding asciiencoding = new ASCIIEncoding();
//Convert the first 8 to chars to bytes and the last
//8 chars to bytes ignore the middle
asciiencoding.GetBytes(newkey, start, key.Length, key, 0);
start = newkey.Length - iv.Length;
asciiencoding.GetBytes(newkey, start, iv.Length, iv, 0);
}
示例14: TokenGenerator
public TokenGenerator(String ResourceLocation, String Secret, UInt16 Generator)
{
ASCIIEncoding AsciiEncoder = new ASCIIEncoding();
this.Generator = Generator;
this.key = AsciiEncoder.GetBytes(Secret);
this.message = AsciiEncoder.GetBytes(ResourceLocation);
this.HMACSHA1Generator = new HMACSHA1(this.key);
this.mac = this.HMACSHA1Generator.ComputeHash(this.message);
}
示例15: getInvoice
public String getInvoice()
{
TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1);
int secondsSinceEpoch = (int)t.TotalSeconds;
String json = "{\"nonce\": " + secondsSinceEpoch + ", \"method\": \"invoice\"}";
//Encode the json version of the parameters above
var convertedParam = Convert.ToBase64String(Encoding.UTF8.GetBytes(json));
//Encrypt the parameters with sha256 using the secret as the key
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] keyByte = encoding.GetBytes(secret);
HMACSHA256 hmacsha256 = new HMACSHA256(keyByte);
byte[] messageBytes = encoding.GetBytes(convertedParam);
byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
//Create the signature, a hex output of the encrypted hash above
StringBuilder stringBuilder = new StringBuilder();
foreach (byte b in hashmessage)
{
stringBuilder.AppendFormat("{0:X2}", b);
}
string signature = stringBuilder.ToString().ToLower();
String url = baseUrl + "/api/invoice";
WebRequest theRequest = WebRequest.Create(url);
theRequest.Method = "POST";
theRequest.ContentType = "text/x-json";
theRequest.ContentLength = json.Length;
theRequest.Headers["X-DIGITALX-KEY"] = key;
theRequest.Headers["X-DIGITALX-PARAMS"] = convertedParam;
theRequest.Headers["X-DIGITALX-SIGNATURE"] = signature;
Stream requestStream = theRequest.GetRequestStream();
requestStream.Write(Encoding.ASCII.GetBytes(json), 0, json.Length);
requestStream.Close();
HttpWebResponse response = (HttpWebResponse)theRequest.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader myStreamReader = new StreamReader(responseStream, Encoding.Default);
string pageContent = myStreamReader.ReadToEnd();
myStreamReader.Close();
responseStream.Close();
response.Close();
return pageContent;
}