當前位置: 首頁>>代碼示例>>C#>>正文


C# Encoding.GetBytes方法代碼示例

本文整理匯總了C#中System.Text.Encoding.GetBytes方法的典型用法代碼示例。如果您正苦於以下問題:C# Encoding.GetBytes方法的具體用法?C# Encoding.GetBytes怎麽用?C# Encoding.GetBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Text.Encoding的用法示例。


在下文中一共展示了Encoding.GetBytes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ProcessCommand

        public static void ProcessCommand(string command, Stream io, int security, string user, Encoding encoding)
        {
            if (String.IsNullOrWhiteSpace(command))
            {
                return;
            }

            try
            {
                byte[] writebuffer;

                var cmdsplit = command.Split(' ');
                if (cmdsplit.Length < 1) return;
                var label = cmdsplit[0];

                if (SBWAPI.PluginManager.Default.ProcessCommand(label, command, io, security, user, encoding)) return;

                if (command.StartsWith("#"))
                {
                    if (security < 4)
                    {
                        writebuffer =
                            encoding.GetBytes(
                                "\u001B[31mYou do not have permission to send special commands\u001B[0m\r\n");
                        io.Write(writebuffer, 0, writebuffer.Length);
                        return;
                    }

                    if (CommandProcessors.ContainsKey(label))
                        CommandProcessors[label](command, io, security, user, encoding);
                    return;
                }
                if (command.StartsWith("/"))
                {
                    if (security < 3)
                    {
                        writebuffer = encoding.GetBytes(
                            "\u001B[31mYou do not have permission to send commands\u001B[0m\r\n");
                        io.Write(writebuffer, 0, writebuffer.Length);
                        return;
                    }

                    if (CommandProcessors.ContainsKey(label))
                        CommandProcessors[label](command, io, security, user, encoding);
                    else
                    {
                        ServerHandler.ProcessHandler.ExtOutput(string.Format("<{0}> {1}", user, command));
                        ServerHandler.ProcessHandler.Instance.Command(command.Remove(0, 1));
                    }
                    return;
                }

                CommandProcessors["\uFFFF"](command, io, security, user, encoding);
            }
            catch
            {
            }
        }
開發者ID:Connorcpu,項目名稱:SimpleBukkitWrapper,代碼行數:58,代碼來源:CommandHandlers.cs

示例2: BoundaryStreamReader

        public BoundaryStreamReader(string boundary, Stream baseStream, Encoding streamEncoding, int bufferLength)
        {
            if (baseStream == null)
            {
                throw new ArgumentNullException("baseStream");
            }

            if (!baseStream.CanSeek || !baseStream.CanRead)
            {
                throw new ArgumentException("baseStream must be a seekable readable stream.");
            }

            if (bufferLength < boundary.Length + 6)
            {
                throw new ArgumentOutOfRangeException(
                    "bufferLength",
                    "The buffer needs to be big enough to contain the boundary and control characters (6 bytes)");
            }

            this.Log = NullLogger<IOLogSource>.Instance;
            this.BaseStream = baseStream;

            // by default if unspecified an encoding should be ascii
            // some people are of the opinion that utf-8 should be parsed by default
            // or that it should depend on the source page.
            // Need to test what browsers do in the wild.
            Encoding = streamEncoding;
            Encoding.GetBytes("--" + boundary);
            this.beginBoundary = Encoding.GetBytes("\r\n--" + boundary);
            this.localBuffer = new byte[bufferLength];
            this.beginBoundaryAsString = "--" + boundary;
            this.AtPreamble = true;
        }
開發者ID:endjin,項目名稱:openrasta-stable,代碼行數:33,代碼來源:BoundaryStreamReader.cs

示例3: Write

        //--- Extension Methods ---

        /// <summary>
        /// Write a string to <see cref="Stream"/>
        /// </summary>
        /// <param name="stream">Target <see cref="Stream"/></param>
        /// <param name="encoding">Encoding to use to convert the string to bytes</param>
        /// <param name="text">Regular string or composite format string to write to the <see cref="Stream"/></param>
        /// <param name="args">An System.Object array containing zero or more objects to format.</param>
        public static void Write(this Stream stream, Encoding encoding, string text, params object[] args) {
            const int bufferSize = BUFFER_SIZE / sizeof(char);
            if(text.Length > bufferSize) {

                // to avoid a allocating a byte array of greater than 64k, we chunk our string writing here
                if(args.Length != 0) {
                    text = string.Format(text, args);
                }
                var length = text.Length;
                var idx = 0;
                var buffer = new char[bufferSize];
                while(true) {
                    var size = Math.Min(bufferSize, length - idx);
                    if(size == 0) {
                        break;
                    }
                    text.CopyTo(idx, buffer, 0, size);
                    stream.Write(encoding.GetBytes(buffer, 0, size));
                    idx += size;
                }
            } else {
                if(args.Length == 0) {
                    stream.Write(encoding.GetBytes(text));
                } else {
                    stream.Write(encoding.GetBytes(string.Format(text, args)));
                }
            }
        }
開發者ID:nataren,項目名稱:DReAM,代碼行數:37,代碼來源:StreamUtil.cs

示例4: Encrypt

        /// <summary>
        ///    aes 加密
        /// </summary>
        /// <param name="toEncrypt"></param>
        /// <param name="key"></param>
        /// <param name="encoding">加密編碼方式    默認為   utf-8  </param>
        /// <returns></returns>
        public static string Encrypt(string toEncrypt, string key, Encoding encoding = null)
        {
            string result = string.Empty;

            if (string.IsNullOrEmpty(key))
                throw new ArgumentNullException("key", "key值不能為空");

            if (string.IsNullOrEmpty(toEncrypt))
                return result;

            if (encoding==null)
                encoding=Encoding.UTF8;

            try
            {
                byte[] keyArray = encoding.GetBytes(key);// ToByte(key);
                byte[] toEncryptArray = encoding.GetBytes(toEncrypt);
                var resultArray = Encrypt(keyArray, toEncryptArray);
                result = Convert.ToBase64String(resultArray);
            }
            catch
            {

            }
            return result;
        }
開發者ID:KevinWG,項目名稱:OS.Common,代碼行數:33,代碼來源:AESRijndael.cs

示例5: MultipartWriter

 public MultipartWriter(string boundary, Stream underlyingStream, Encoding encoding)
 {
     _boundary = boundary;
     _underlyingStream = underlyingStream;
     _encoding = encoding;
     _beginBoundary = encoding.GetBytes("--" + boundary +"\r\n" );
     _endBoundary = encoding.GetBytes("\r\n--" + boundary + "--\r\n");
 }
開發者ID:dhootha,項目名稱:openrasta-core,代碼行數:8,代碼來源:MultipartWriter.cs

示例6: ParseView

 public byte[] ParseView(IView view, string viewTemplate, Encoding encoding)
 {
     if (File.Exists(viewTemplate))
     {
         return encoding.GetBytes(File.ReadAllText(viewTemplate));
     }
     return encoding.GetBytes(viewTemplate + " not found");
 }
開發者ID:dotnet-koelnbonn,項目名稱:ThereIsAThing,代碼行數:8,代碼來源:ViewParser.cs

示例7: MultipartWriter

 public MultipartWriter(string boundary, Stream underlyingStream, Encoding encoding)
 {
     this.boundary = boundary;
     this.underlyingStream = underlyingStream;
     this.encoding = encoding;
     this.beginBoundary = encoding.GetBytes("--" + boundary + "\r\n");
     this.endBoundary = encoding.GetBytes("\r\n--" + boundary + "--\r\n");
 }
開發者ID:endjin,項目名稱:openrasta-stable,代碼行數:8,代碼來源:MultipartWriter.cs

示例8: HMACMD5

        /// <summary>
        /// Creates an HMAC-MD5 fingerprint of the given data with the given key using the specified encoding
        /// </summary>
        /// <param name="data"></param>
        /// <param name="key"></param>
        /// <param name="enc"></param>
        /// <returns></returns>
        public static string HMACMD5(this string data, string key, Encoding enc)
        {
            var hmacKey = enc.GetBytes(key);
            var hmacData = enc.GetBytes(data);

            using (var hmacMd5 = new HMACMD5(hmacKey)) {
                return hmacMd5.ComputeHash(hmacData).ToHex().ToLower();
            }
        }
開發者ID:veracross,項目名稱:ncontrib,代碼行數:16,代碼來源:StringCryptographyExtensions.cs

示例9: StaticContentFilter

        public StaticContentFilter(HttpResponse response, string imagePrefix, string javascriptPrefix, string cssPrefix)
        {
            this._Encoding = response.Output.Encoding;
            this._ResponseStream = response.Filter;

            this._ImagePrefix = _Encoding.GetBytes(imagePrefix);
            this._JavascriptPrefix = _Encoding.GetBytes(javascriptPrefix);
            this._CssPrefix = _Encoding.GetBytes(cssPrefix);
        }
開發者ID:haimon74,項目名稱:KanNaim,代碼行數:9,代碼來源:StaticContentFilter.cs

示例10: CompressToByte

        public static byte[] CompressToByte(char[] str, bool needheadflag, Encoding enc)
        {            
            if (str.Length < zipsizemin) return enc.GetBytes(str);

            Byte[] bTytes = enc.GetBytes(str);
            Byte[] retbytes = Compress(bTytes, needheadflag, enc);

            return retbytes;
        }
開發者ID:szlfwolf,項目名稱:FZF,代碼行數:9,代碼來源:CompressUtiliy.cs

示例11: Authenticate

        public static int Authenticate(string user, string pass, Stream status, Encoding encoding)
        {
            var passhash = Sha1Hash(pass);
            byte[] b;

            if (Config.UserCache[user + "§custom"] == "true")
            {
                
                b = encoding.GetBytes("\u001B[36mAuthenticating against local hash...\u001B[0m\r\n");
                status.Write(b, 0, b.Length);

                if (passhash != Config.UserCache[user + "§hash"])
                {
                    return -1;
                }

                int seclvlc;
                var prc = int.TryParse(Config.UserCache[user], out seclvlc);
                return prc ? seclvlc : 0;
            }

            b = encoding.GetBytes("\u001B[36mAuthenticating with minecraft.net\r\n");
            status.Write(b, 0, b.Length);

            var olresult = ValidateOnline(user, pass);

            if (olresult == null)
            {
                b=encoding.GetBytes("\u001B[31mError connecting to minecraft.net\r\n");
                status.Write(b, 0, b.Length);
                b = encoding.GetBytes("\u001B[36mAuthenticating against local cache...\u001B[0m\r\n");
                status.Write(b, 0, b.Length);
                if (Config.UserCache[user + "§hash"] != "")
                {
                    if (passhash == Config.UserCache[user + "§hash"])
                    {
                        olresult = true;
                    }
                    else return -1;
                }
                else
                {
                    b = encoding.GetBytes("\u001B[31mPassword not availible in cache\u001B[0m\r\n");
                    status.Write(b, 0, b.Length);
                    return -1;
                }
            }

            if (olresult == false) return -1;

            Config.UserCache[user + "§hash"] = passhash;

            int seclvl;
            var pr = int.TryParse(Config.UserCache[user], out seclvl);
            return pr ? seclvl : 0;
        }
開發者ID:Connorcpu,項目名稱:SimpleBukkitWrapper,代碼行數:56,代碼來源:AuthProvider.cs

示例12: WriteStringInternalDynamic

        internal static void WriteStringInternalDynamic(this Stream stream, Encoding encoding, string value, char end)
        {
            byte[] data;
            
            data = encoding.GetBytes(value);
            stream.Write(data, 0, data.Length);

            data = encoding.GetBytes(end.ToString());
            stream.Write(data, 0, data.Length);
        }
開發者ID:nortex,項目名稱:d3sharp,代碼行數:10,代碼來源:Internal.cs

示例13: DoEncrypt

        /// <summary>
        /// 
        /// </summary>
        /// <param name="plainText"></param>
        /// <param name="key"></param>
        /// <param name="encoding"></param>
        /// <param name="encryptedType"></param>
        /// <returns></returns>
        public override string DoEncrypt(string plainText, string key, Encoding encoding, DataMode encryptedType)
        {
            byte[] keyByte = encoding.GetBytes(key);
            HMACMD5 hmacMD5 = new HMACMD5(keyByte);

            byte[] messageBytes = encoding.GetBytes(plainText);
            byte[] hashMessage = hmacMD5.ComputeHash(messageBytes);

            return BytesToString(hashMessage, encoding, encryptedType);
        }
開發者ID:weiliji,項目名稱:MyFramework,代碼行數:18,代碼來源:HMACMD5HashCryptographer.cs

示例14: StreamingMultiPartParser

 private StreamingMultiPartParser(Stream bodyStream, Encoding encoding, string boundary, byte[] outerBoundary, Buffer buffer)
 {
     this.bodyStream = bodyStream;
     this.encoding = encoding;
     this.boundary = encoding.GetBytes("--" + boundary);
     this.outerBoundary = outerBoundary;
     this.dashes = encoding.GetBytes("--");
     this.newLine = encoding.GetBytes("\r\n");
     this.buffer = buffer;
 }
開發者ID:jehugaleahsa,項目名稱:NRest,代碼行數:10,代碼來源:StreamingMultiPartParser.cs

示例15: CheckCharCode

        /// <summary>コンストラクタ</summary>
        public CheckCharCode(string startChar, string endChar, Encoding stringEncoding)
        {
            this.StartChar = startChar;
            this.EndChar = endChar;
            this.StringEncoding = stringEncoding;

            // 1文字のバイトデータを數値データ(long)に変換
            this.StartCode = PubCmnFunction.GetLongFromByte(stringEncoding.GetBytes(startChar));
            this.EndCode = PubCmnFunction.GetLongFromByte(stringEncoding.GetBytes(endChar));
        }
開發者ID:krt,項目名稱:OpenTouryo,代碼行數:11,代碼來源:CheckCharCode.cs


注:本文中的System.Text.Encoding.GetBytes方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。