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


C# ASCIIEncoding.GetBytes方法代码示例

本文整理汇总了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);
 }
开发者ID:micheljung,项目名称:gpgnetfix,代码行数:7,代码来源:Crypto.cs

示例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");
        }
开发者ID:ulricheza,项目名称:Isima,代码行数:30,代码来源:UnitTestReceivePrivateMessage.cs

示例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;
        }
开发者ID:macchicken,项目名称:MobileWorkManagement,代码行数:28,代码来源:Utility.cs

示例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);
        }
开发者ID:vaginessa,项目名称:Simsang,代码行数:40,代码来源:ContributeHTTP.cs

示例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");
        }
开发者ID:ulricheza,项目名称:Isima,代码行数:27,代码来源:UnitTestSendPrivateMessage.cs

示例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));
        }
开发者ID:nextxyz,项目名称:first-person-practice,代码行数:60,代码来源:Program.cs

示例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);
        }
开发者ID:mattruma,项目名称:web-api,代码行数:8,代码来源:CryptographyHelper.cs

示例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;
         }
     }
 }
开发者ID:kr4ckl3s,项目名称:capstone,代码行数:58,代码来源:GraphicCode.cs

示例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;
        }
开发者ID:Jake1305,项目名称:SourceRcon,代码行数:57,代码来源:RCONPacket.cs

示例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);
        }
开发者ID:sidorovsacha,项目名称:Smart-house,代码行数:56,代码来源:SocketServer.cs

示例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";
 }
开发者ID:osiato,项目名称:LegendaryClient,代码行数:10,代码来源:LeagueDownloadLogic.cs

示例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('=');
 }
开发者ID:tvhnet2014,项目名称:stream-net,代码行数:10,代码来源:StreamClient.cs

示例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);
 }
开发者ID:wamacs,项目名称:GSN,代码行数:10,代码来源:LegacyCryptoKey.cs

示例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);
        }
开发者ID:swiftserve,项目名称:reference-configuration,代码行数:11,代码来源:TokenGen.cs

示例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;
        }
开发者ID:neel-digitalbtc,项目名称:digitalx-c-sharp,代码行数:54,代码来源:DigitalXWrapper.cs


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