当前位置: 首页>>代码示例>>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;未经允许,请勿转载。