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


C# System.IO.MemoryStream.Close方法代码示例

本文整理汇总了C#中System.IO.MemoryStream.Close方法的典型用法代码示例。如果您正苦于以下问题:C# System.IO.MemoryStream.Close方法的具体用法?C# System.IO.MemoryStream.Close怎么用?C# System.IO.MemoryStream.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.MemoryStream的用法示例。


在下文中一共展示了System.IO.MemoryStream.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Encrypt

        /// <summary>
        /// 加密字符串
        /// </summary>
        public static string Encrypt(string PlainText)
        {
            System.Security.Cryptography.DESCryptoServiceProvider key = new System.Security.Cryptography.DESCryptoServiceProvider();
            byte[] bk = System.Text.Encoding.Unicode.GetBytes(CryKey);
            byte[] bs = new byte[8];
            for (int i = 0; i < bs.Length; i++)
            {
                bs[i] = bk[i];
            }
            key.Key = bs;
            key.IV = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 };

            System.IO.MemoryStream ms = new System.IO.MemoryStream();

            System.Security.Cryptography.CryptoStream encStream = new System.Security.Cryptography.CryptoStream(ms, key.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write);

            System.IO.StreamWriter sw = new System.IO.StreamWriter(encStream);
            sw.WriteLine(PlainText);
            sw.Close();
            encStream.Close();

            byte[] buffer = ms.ToArray();
            ms.Close();

            string s = "";
            for (int i = 0; i < buffer.Length; i++)
            {
                s += buffer[i].ToString("X2");
            }
            return s;
        }
开发者ID:JasonDevStudio,项目名称:CodeGeneration,代码行数:34,代码来源:EncryptDecrypt.cs

示例2: Decrypt

        private static string CryKey = "Xky_Lq_Py_Hu_Lp_Jhj_Zxt"; //密钥

        #endregion Fields

        #region Methods

        /// <summary>
        /// 解密字符串
        /// </summary>
        public static string Decrypt(string CypherText)
        {
            System.Security.Cryptography.DESCryptoServiceProvider key = new System.Security.Cryptography.DESCryptoServiceProvider();
            byte[] bk = System.Text.Encoding.Unicode.GetBytes(CryKey);
            byte[] bs = new byte[8];
            for (int i = 0; i < bs.Length; i++)
            {
                bs[i] = bk[i];
            }
            key.Key = bs;
            key.IV = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 };

            byte[] bc = new byte[CypherText.Length / 2];
            for (int i = 0; i < bc.Length; i++)
            {
                try
                {
                    bc[i] = Convert.ToByte(CypherText.Substring(2 * i, 2), 16);
                }
                catch { }
            }
            System.IO.MemoryStream ms = new System.IO.MemoryStream(bc);
            System.Security.Cryptography.CryptoStream encStream = new System.Security.Cryptography.CryptoStream(ms, key.CreateDecryptor(), System.Security.Cryptography.CryptoStreamMode.Read);
            System.IO.StreamReader sr = new System.IO.StreamReader(encStream);

            string val = sr.ReadLine();

            sr.Close();
            encStream.Close();
            ms.Close();

            return val;
        }
开发者ID:JasonDevStudio,项目名称:CodeGeneration,代码行数:42,代码来源:EncryptDecrypt.cs

示例3: Encrypt

 /// <summary>
 /// DES encryption
 /// </summary>
 /// <param name="strToEncrypt"></param>
 /// <param name="sKey">the key length must equals 8</param>
 /// <returns> Base64 format</returns>
 public string Encrypt(string strToEncrypt, string sKey)
 {
     if (sKey.Length > 8)
     {
         throw new Exception("the key length must be less than or equal to 8!");
     }
     if (sKey.Length < 8)
     {
         string sKeyOther = "abcdefgh";
         sKey += sKeyOther.Substring(0, 8 - sKey.Length);
     }
     using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
     {
         byte[] inputByteArray = Encoding.UTF8.GetBytes(strToEncrypt);
         des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
         des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
         System.IO.MemoryStream ms = new System.IO.MemoryStream();
         using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write))
         {
             cs.Write(inputByteArray, 0, inputByteArray.Length);
             cs.FlushFinalBlock();
             cs.Close();
         }
         string str = Convert.ToBase64String(ms.ToArray());
         ms.Close();
         return str;
     }
 }
开发者ID:flyeven,项目名称:Utility,代码行数:34,代码来源:Security.cs

示例4: Decrypt

        /// <summary>
        /// DES decryption  --by edgar on 2013-9-10
        /// </summary>
        /// <param name="strToDecrypt"></param>
        /// <param name="sKey">the key's length must equals 8</param>
        /// <returns></returns>
        public string Decrypt(string strToDecrypt, string sKey)
        {
            if (sKey.Length < 8)
            {
                string sKeyOther = "abcdefgh";
                sKey += sKeyOther.Substring(0, 8 - sKey.Length);
            }

            byte[] inputByteArray = Convert.FromBase64String(strToDecrypt);
            using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
            {
                des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
                des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write))
                {
                    cs.Write(inputByteArray, 0, inputByteArray.Length);
                    cs.FlushFinalBlock();
                    cs.Close();
                }
                string str = Encoding.UTF8.GetString(ms.ToArray());
                ms.Close();
                return str;
            }
        }
开发者ID:flyeven,项目名称:Utility,代码行数:31,代码来源:Security.cs

示例5: recv

 public string recv()
 {
     System.Text.Encoding enc = System.Text.Encoding.UTF8;
     //サーバーから送られたデータを受信する
     System.IO.MemoryStream ms = new System.IO.MemoryStream();
     byte[] resBytes = new byte[1];
     int resSize;
     ns.ReadTimeout = 100;
     do
     {
         //データの一部を受信する
         resSize = ns.Read(resBytes,0,1);
         //Readが0を返した時はサーバーが切断したと判断
         if (resSize == 0)
         {
             Console.WriteLine("サーバーが切断しました。");
             return "";
         }
         if (resBytes[0] == ';')
         {
             break;
         }
         //受信したデータを蓄積する
         ms.Write(resBytes, 0,1);
         
     } while (ns.DataAvailable);
     //受信したデータを文字列に変換
     string resMsg = enc.GetString(ms.ToArray());
     ms.Close();
     Console.WriteLine(resMsg);
     return resMsg;
 }
开发者ID:naegawa,项目名称:RobotController,代码行数:32,代码来源:RobotController.cs

示例6: SendMessage

        private static void SendMessage(object radarData)
        {
            try
            {
                if (server == null || server.continueUpdate)
                {
                    server = new Server(Common.ServerPort);
                    server.Start();
                }
                var data = (radarData as RadarData);

                if (data == null) return;

                if (Common.IgnoreWoWWindowActive)
                {
                    data.IsWowWindowActive = true;
                }

                byte[] buffer = null;
                using (var ms = new System.IO.MemoryStream())
                {
                    BlackRain.Serialization.BinarySerializer.SerializeObject<RadarData>(ms, data);
                    buffer = ms.GetBuffer();
                    ms.Close();
                }
                server.SendMessage(buffer);
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc.Message);
            }
        }
开发者ID:RaptorFactor,项目名称:devmaximus,代码行数:32,代码来源:Program.cs

示例7: SerializeVoxelAreaData

		public static byte[] SerializeVoxelAreaData (VoxelArea v) {
#if !ASTAR_RECAST_CLASS_BASED_LINKED_LIST
			System.IO.MemoryStream stream = new System.IO.MemoryStream();
			System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
			
			writer.Write (v.width);
			writer.Write (v.depth);
			writer.Write (v.linkedSpans.Length);
			
			for (int i=0;i<v.linkedSpans.Length;i++) {
				writer.Write(v.linkedSpans[i].area);
				writer.Write(v.linkedSpans[i].bottom);
				writer.Write(v.linkedSpans[i].next);
				writer.Write(v.linkedSpans[i].top);
			}
			
			//writer.Close();
			writer.Flush();
			Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile();
			stream.Position = 0;
			zip.AddEntry ("data",stream);
			System.IO.MemoryStream stream2 = new System.IO.MemoryStream();
			zip.Save(stream2);
			byte[] bytes = stream2.ToArray();
			stream.Close();
			stream2.Close();
			return bytes;
#else
			throw new System.NotImplementedException ("This method only works with !ASTAR_RECAST_CLASS_BASED_LINKED_LIST");
#endif
		}
开发者ID:SpacesAdventure,项目名称:Kio-2,代码行数:31,代码来源:VoxelClasses.cs

示例8: CloseAndFlush

        public void CloseAndFlush()
        {
            var memStream = new System.IO.MemoryStream();

            memStream.Close();
            memStream.Flush();
        }
开发者ID:james-andrewsmith,项目名称:Fos,代码行数:7,代码来源:Startup.cs

示例9: GetBitmap

        /// <summary>
        /// Converts a byte array to a bitmap
        /// </summary>
        /// <param name="bytes"></param>
        /// <returns></returns>
        public static Bitmap GetBitmap(byte[] bytes)
        {
            if (bytes == null)
                return null;

            if (bytes.Length == 0)
                return null;

            System.IO.MemoryStream stream = new System.IO.MemoryStream(bytes);
            Bitmap b = new Bitmap(stream);
            stream.Close();
            try
            {
                return (Bitmap)b.Clone();
            }
            catch(Exception ex)
            {
                Trace.WriteLine(ex);
            }
            finally
            {
                b.Dispose();
            }
            return null;
        }
开发者ID:luisbebop,项目名称:svchost,代码行数:30,代码来源:ScreenCapturing.cs

示例10: EncryptString

                //static Logger logger = SimpleLogger.setLogger("Common");

                #region �Í����֌W

                /// <summary>
                /// ��������������
                /// </summary>
                /// <param name="str">�Í������镶����</param>
                /// <param name="key">�p�X���[�h</param>
                /// <returns>�Í������ꂽ������</returns>
                public static string EncryptString(string str, string key)
                {
                    //�������o�C�g�^�z��ɂ���
                    byte[] bytesIn = System.Text.Encoding.UTF8.GetBytes(str);

                    //DESCryptoServiceProvider�I�u�W�F�N�g�̍쐬
                    System.Security.Cryptography.DESCryptoServiceProvider des = new System.Security.Cryptography.DESCryptoServiceProvider();

                    //���L�L�[�Ə������x�N�^�����
                    //�p�X���[�h��o�C�g�z��ɂ���
                    byte[] bytesKey = System.Text.Encoding.UTF8.GetBytes(key);
                    //���L�L�[�Ə������x�N�^��ݒ�
                    des.Key = ResizeBytesArray(bytesKey, des.Key.Length);
                    des.IV = ResizeBytesArray(bytesKey, des.IV.Length);

                    //�Í������ꂽ�f�[�^������o�����߂�MemoryStream
                    MemoryStream msOut = new System.IO.MemoryStream();
                    //DES�Í����I�u�W�F�N�g�̍쐬
                    System.Security.Cryptography.ICryptoTransform desdecrypt = des.CreateEncryptor();
                    //�������ނ��߂�CryptoStream�̍쐬
                    System.Security.Cryptography.CryptoStream cryptStreem = new System.Security.Cryptography.CryptoStream(msOut, desdecrypt, System.Security.Cryptography.CryptoStreamMode.Write);
                    //��������
                    cryptStreem.Write(bytesIn, 0, bytesIn.Length);
                    cryptStreem.FlushFinalBlock();
                    //�Í������ꂽ�f�[�^��擾
                    byte[] bytesOut = msOut.ToArray();

                    //�‚���
                    cryptStreem.Close();
                    msOut.Close();

                    //Base64�ŕ�����ɕύX���Č��ʂ�Ԃ�
                    return System.Convert.ToBase64String(bytesOut).Replace("=", "");
                }
开发者ID:anon5r,项目名称:TSLoginManager,代码行数:44,代码来源:CommonController.cs

示例11: recive

        public string recive()
        {
            System.Text.Encoding enc = System.Text.Encoding.UTF8;
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            byte[] resBytes = new byte[256];
            int resSize = 0;

            if (ns.DataAvailable)
            {

                do
                {
                    //データの一部を受信する
                    resSize = ns.Read(resBytes, 0, resBytes.Length);

                    //受信したデータを蓄積する
                    ms.Write(resBytes, 0, resSize);

                    // 受信を続ける
                } while (ns.DataAvailable || resBytes[resSize - 1] != '\n');

                //受信したデータを文字列に変換
                string resMsg = enc.GetString(ms.GetBuffer(), 0, (int)ms.Length);
                ms.Close();
                //末尾の\nを削除
                resMsg = resMsg.TrimEnd('\n');

                return resMsg;
            }
            else
            {
                return "0";
            }
        }
开发者ID:kousokujin,项目名称:RemoteTaskManagerServer,代码行数:34,代码来源:tcp_connection.cs

示例12: Form1_Load

 private void Form1_Load(object sender, EventArgs e)
 {
     String pic = "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDABMNDxEPDBMREBEWFRMXHTAfHRsbHTsqLSMwRj5KSUU+RENNV29eTVJpU0NEYYRiaXN3fX59S12Jkoh5kW96fXj/2wBDARUWFh0ZHTkfHzl4UERQeHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHj/wAARCAAfACEDAREAAhEBAxEB/8QAGAABAQEBAQAAAAAAAAAAAAAAAAQDBQb/xAAjEAACAgICAgEFAAAAAAAAAAABAgADBBESIRMxBSIyQXGB/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/APawEBAQEBAgy8i8ZTVV3UY6V1eU2XoWDDZB19S646Gz39w9fkKsW1r8Wm2yo1PYis1be0JG9H9QNYCAgc35Cl3yuVuJZl0cB41rZQa32dt2y6OuOiOxo61vsLcVblxaVyXD3hFFjL6La7I/sDWAgICAgICB/9k=";
     System.IO.MemoryStream memoryStream = new System.IO.MemoryStream(Convert.FromBase64String(pic));
     this.pictureBox1.Image = new System.Drawing.Bitmap(memoryStream);
     memoryStream.Close();
 }
开发者ID:SpeakHero,项目名称:WeChatPlatform,代码行数:7,代码来源:Form1.cs

示例13: UnZipCompress

        public static string UnZipCompress(this string value)
        {
            //Transform string into byte[]
            byte[] byteArray = new byte[value.Length];
            int indexBA = 0;
            foreach (char item in value.ToCharArray())
            {
                byteArray[indexBA++] = (byte)item;
            }

            //Prepare for decompress
            System.IO.MemoryStream ms = new System.IO.MemoryStream(byteArray);
            System.IO.Compression.GZipStream sr = new System.IO.Compression.GZipStream(ms,
                System.IO.Compression.CompressionMode.Decompress);

            //Reset variable to collect uncompressed result
            byteArray = new byte[byteArray.Length];

            //Decompress
            int rByte = sr.Read(byteArray, 0, byteArray.Length);

            //Transform byte[] unzip data to string
            System.Text.StringBuilder sB = new System.Text.StringBuilder(rByte);
            //Read the number of bytes GZipStream red and do not a for each bytes in
            //resultByteArray;
            for (int i = 0; i < rByte; i++)
            {
                sB.Append((char)byteArray[i]);
            }
            sr.Close();
            ms.Close();
            sr.Dispose();
            ms.Dispose();
            return sB.ToString();
        }
开发者ID:Cyberbanan,项目名称:voxeliq,代码行数:35,代码来源:StringExtensions.cs

示例14: ZipCompress

        public static string ZipCompress(this string value)
        {
            //Transform string into byte[]  
            byte[] byteArray = new byte[value.Length];
            int indexBA = 0;
            foreach (char item in value.ToCharArray())
            {
                byteArray[indexBA++] = (byte)item;
            }

            //Prepare for compress
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            System.IO.Compression.GZipStream sw = new System.IO.Compression.GZipStream(ms,
                System.IO.Compression.CompressionMode.Compress);

            //Compress
            sw.Write(byteArray, 0, byteArray.Length);
            //Close, DO NOT FLUSH cause bytes will go missing...
            sw.Close();

            //Transform byte[] zip data to string
            byteArray = ms.ToArray();
            System.Text.StringBuilder sB = new System.Text.StringBuilder(byteArray.Length);
            foreach (byte item in byteArray)
            {
                sB.Append((char)item);
            }
            ms.Close();
            sw.Dispose();
            ms.Dispose();
            return sB.ToString();
        }
开发者ID:Cyberbanan,项目名称:voxeliq,代码行数:32,代码来源:StringExtensions.cs

示例15: Thumbize

        public static void Thumbize(string pPage, string pThumb, Document document, Page page)
        {
            System.IO.MemoryStream cryptoStream = new System.IO.MemoryStream(Utility.Security.AES.DecryptStream(page.Token, System.IO.File.ReadAllBytes(System.IO.Path.Combine(pPage, page.Filename))).ToArray());
            using (var srcImage = System.Drawing.Image.FromStream(cryptoStream))
            {
                var newWidth = 300;
                var newHeight = 200;

                using (var newImage = new Bitmap(newWidth, newHeight))
                using (var graphics = Graphics.FromImage(newImage))
                {
                    graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                    graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                    graphics.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                    graphics.DrawImage(srcImage, new System.Drawing.Rectangle(0, 0, newWidth, newHeight));

                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    System.Drawing.Imaging.EncoderParameters parms = new System.Drawing.Imaging.EncoderParameters(1);
                    parms.Param[0] = new System.Drawing.Imaging.EncoderParameter(System.Drawing.Imaging.Encoder.Compression, 0);
                    System.Drawing.Imaging.ImageCodecInfo jpegEncoder = System.Drawing.Imaging.ImageCodecInfo.GetImageEncoders().FirstOrDefault(e => e.FormatDescription == "JPEG");
                    newImage.Save(ms, jpegEncoder, parms);
                    System.IO.File.WriteAllBytes(System.IO.Path.Combine(pThumb, string.Format("{0}.jpg", document.Id.ToString())), SoftFluent.Samples.GED.Utility.Security.AES.EncryptStream(document.Token, ms.ToArray()).ToArray());
                    ms.Close();
                }
            }
        }
开发者ID:modulexcite,项目名称:CodeFluent-Entities,代码行数:26,代码来源:Treatment.cs


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