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


C# MemoryStream类代码示例

本文整理汇总了C#中MemoryStream的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream类的具体用法?C# MemoryStream怎么用?C# MemoryStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: TestKnownEnc

    static Boolean TestKnownEnc(Aes aes, Byte[] Key, Byte[] IV, Byte[] Plain, Byte[] Cipher)
    {

        Byte[]  CipherCalculated;
        
        Console.WriteLine("Encrypting the following bytes:");
        PrintByteArray(Plain);
        Console.WriteLine("With the following Key:");
        PrintByteArray(Key);
        Console.WriteLine("and IV:");
        PrintByteArray(IV);
 		Console.WriteLine("Expecting this ciphertext:");
		PrintByteArray(Cipher);        
        
        ICryptoTransform sse = aes.CreateEncryptor(Key, IV);
        MemoryStream 	ms = new MemoryStream();
        CryptoStream    cs = new CryptoStream(ms, sse, CryptoStreamMode.Write);
        cs.Write(Plain,0,Plain.Length);
        cs.FlushFinalBlock();
        CipherCalculated = ms.ToArray();
        cs.Close();

		Console.WriteLine("Computed this cyphertext:");
        PrintByteArray(CipherCalculated);
        

        if (!Compare(Cipher, CipherCalculated)) {
        	Console.WriteLine("ERROR: result is different from the expected");
        	return false;
        }
        
        Console.WriteLine("OK");
        return true;
    }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:34,代码来源:AESKnownEnc2.cs

示例2: OnMsgConstellationLevelup

 public void OnMsgConstellationLevelup(MemoryStream stream)
 {
     MS2C_ConstellationLevelup mS2C_ConstellationLevelup = Serializer.NonGeneric.Deserialize(typeof(MS2C_ConstellationLevelup), stream) as MS2C_ConstellationLevelup;
     if (mS2C_ConstellationLevelup.Result != 0)
     {
         GameUIManager.mInstance.ShowMessageTip("PlayerR", mS2C_ConstellationLevelup.Result);
         return;
     }
     this.mconLv = Globals.Instance.Player.Data.ConstellationLevel;
     GameUIManager.mInstance.ShowFadeBG(5900, 3000);
     this.mGUIXingZuoPage.mUIXingZuoItem.mWaitTimeToHide = 1.1f;
     this.mGUIXingZuoPage.mUIXingZuoItem.RefreshShowIcon();
     this.mGUIRightInfo.Refresh(this.mconLv);
     this.mGUIXingZuoPage.mUIXingZuoItem.RefreshEffect();
     base.StartCoroutine(this.WaitShowAttribute());
     if (Globals.Instance.Player.ItemSystem.GetItemCount(GameConst.GetInt32(103)) >= GUIRightInfo.GetCost())
     {
         base.StartCoroutine(this.EffectSound());
     }
     int constellationLevel = Globals.Instance.Player.Data.ConstellationLevel;
     if (constellationLevel == 10 || constellationLevel == 30)
     {
         GameUIManager.mInstance.ShowPetQualityUp(constellationLevel);
     }
     if (constellationLevel > 0 && constellationLevel % 5 == 0 && (constellationLevel != 10 & constellationLevel != 30))
     {
         base.StartCoroutine(this.WaitShowBaoXiang());
     }
     Globals.Instance.TutorialMgr.InitializationCompleted(this, null);
 }
开发者ID:floatyears,项目名称:Decrypt,代码行数:30,代码来源:GUIConstellationScene.cs

示例3: NegTest2

    public bool NegTest2() 
    {
        bool retVal = true;
        TestLibrary.TestFramework.BeginScenario("Verify InvalidOperationException is thrown when set ReadTimeOut property...");

        try
        {
            Stream s = new MemoryStream();
            for (int i = 0; i < 100; i++)
                s.WriteByte((byte)i);
            s.Position = 0;

            s.ReadTimeout = 10;

            TestLibrary.TestFramework.LogError("001", "No exception occurs!");
            retVal = false;
        }
        catch (InvalidOperationException)
        {
        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpected exception occurs: " + e);
            retVal = false;
        }

        return retVal;
    }
开发者ID:CheneyWu,项目名称:coreclr,代码行数:28,代码来源:streamreadtimeout.cs

示例4: Decode

    public static ActionPayload Decode(byte[] payload)
    {
        MemoryStream stream = new MemoryStream(payload);
        BinaryReader reader = new BinaryReader(stream);

        byte op = reader.ReadByte ();

        ActionPayload action = new ActionPayload();

        switch (op) {

            case ActionPayload.OP_MOVEMENT:

                action.op = op;
                action.time = reader.ReadSingle ();

                action.position = new Vector3();
                action.position.x = reader.ReadSingle ();
                action.position.y = reader.ReadSingle ();
                action.position.z = reader.ReadSingle ();

                action.rot = reader.ReadSingle ();
                action.state = (int)reader.ReadSingle ();

            break;
        }

        return action;
    }
开发者ID:hydna,项目名称:hydna-unity-chicken-demo,代码行数:29,代码来源:ActionPayload.cs

示例5: CreateMemoryStream

        // Creates a memory stream with the first 4K bytes of the record.
        private void CreateMemoryStream()
        {
            byte[] pData;
            int cbData = INITIAL_READ;
            int totalSize;

            log.ReadRecordPrefix(this.recordSequenceNumber, out pData, ref cbData, out totalSize, out this.prevSeqNum, out this.nextSeqNum);

            if (cbData < FileLogRecordHeader.Size)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.LogCorrupt());

            this.header = new FileLogRecordHeader(pData);
            this.recordSize = totalSize - FileLogRecordHeader.Size;

            int streamSize = Math.Min(this.recordSize,
                                      INITIAL_READ - FileLogRecordHeader.Size);

            this.stream = new MemoryStream(
                pData,
                FileLogRecordHeader.Size,
                streamSize,
                false);

            if (totalSize <= INITIAL_READ)
            {
                // Record is smaller than 4K.  We have read the entire record.
                this.entireRecordRead = true;
            }
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:30,代码来源:FileLogRecordStream.cs

示例6: LoadFromFile

 public void LoadFromFile()
 {
     TextAsset textAsset = Res.Load("Attribute/AchievementInfo") as TextAsset;
     if (textAsset == null)
     {
         global::Debug.LogError(new object[]
         {
             "Res.Load error, Name = AchievementInfo"
         });
         return;
     }
     try
     {
         this.infos.Clear();
         MemoryStream source = new MemoryStream(textAsset.bytes, 0, textAsset.bytes.Length);
         AchievementInfoDict achievementInfoDict = Serializer.NonGeneric.Deserialize(typeof(AchievementInfoDict), source) as AchievementInfoDict;
         for (int i = 0; i < achievementInfoDict.Data.Count; i++)
         {
             this.infos.Add(achievementInfoDict.Data[i].ID, achievementInfoDict.Data[i]);
         }
     }
     catch (Exception ex)
     {
         global::Debug.LogError(new object[]
         {
             "Load AchievementInfo.bytes Error, Exception = " + ex.Message
         });
     }
 }
开发者ID:floatyears,项目名称:Decrypt,代码行数:29,代码来源:AchievementInfoDictionary.cs

示例7: Start

    private void Start()
    {
        string imgFile = folderName + FileUpload1.FileName;
        Stream inputStream = new MemoryStream();
        System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath(imgFile));

        img.Save(inputStream, System.Drawing.Imaging.ImageFormat.Jpeg);

        Stream outputStream;
        int diameter;
        if (int.TryParse(tbDiameter.Text.Trim(), out diameter))
        {
            outputStream = CircleImageCreater.CreateCircleImageStream(inputStream, diameter);
        }
        else
        {
            outputStream = CircleImageCreater.CreateCircleImageStream(inputStream);
        }

        saveImage(outputStream, FileUpload1.FileName + ".png");

        oldImage.ImageUrl = imgFile;
        newImage.ImageUrl = folderName + FileUpload1.FileName + ".png";

        //dispose
        inputStream.Dispose();
        outputStream.Dispose();
    }
开发者ID:hkdilan,项目名称:CreateCircleImage,代码行数:28,代码来源:Default.aspx.cs

示例8: Main

    public static void Main() {
        string PlainText = "Titan";
        byte[] PlainBytes = new byte[5];
        PlainBytes = Encoding.ASCII.GetBytes(PlainText.ToCharArray());
        PrintByteArray(PlainBytes);
        byte[] CipherBytes = new byte[8];
        PasswordDeriveBytes pdb = new PasswordDeriveBytes("Titan", null);
        byte[] IV = new byte[8];
        byte[] Key = pdb.CryptDeriveKey("RC2", "SHA1", 40, IV);
        PrintByteArray(Key);
        PrintByteArray(IV);

        // Now use the data to encrypt something
        RC2CryptoServiceProvider rc2 = new RC2CryptoServiceProvider();
        Console.WriteLine(rc2.Padding);
        Console.WriteLine(rc2.Mode);
        ICryptoTransform sse = rc2.CreateEncryptor(Key, IV);
        MemoryStream ms = new MemoryStream();
        CryptoStream cs1 = new CryptoStream(ms, sse, CryptoStreamMode.Write);
        cs1.Write(PlainBytes, 0, PlainBytes.Length);
        cs1.FlushFinalBlock();
        CipherBytes = ms.ToArray();
        cs1.Close();
        Console.WriteLine(Encoding.ASCII.GetString(CipherBytes));
        PrintByteArray(CipherBytes);

        ICryptoTransform ssd = rc2.CreateDecryptor(Key, IV);
        CryptoStream cs2 = new CryptoStream(new MemoryStream(CipherBytes), ssd, CryptoStreamMode.Read);
        byte[] InitialText = new byte[5];
        cs2.Read(InitialText, 0, 5);
        Console.WriteLine(Encoding.ASCII.GetString(InitialText));
    	PrintByteArray(InitialText);
    }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:33,代码来源:DeriveBytesTest.cs

示例9: DeserializeObject

	public object DeserializeObject(string pXmlizedString , System.Type ty)
	{
		XmlSerializer xs  = new XmlSerializer(ty);
		MemoryStream memoryStream  = new MemoryStream(StringToUTF8ByteArray(pXmlizedString));
		XmlTextWriter xmlTextWriter   = new XmlTextWriter(memoryStream, Encoding.UTF8);
		return xs.Deserialize(memoryStream);
	}
开发者ID:CCCarrion,项目名称:Star-Counter,代码行数:7,代码来源:XmlSaver.cs

示例10: Xor

	//public static string Unscramble(string text ) {
	//	byte[] clear = Encoding.UTF8.GetBytes (text);
	//	return Encoding.UTF8.GetString( Xor( clear) );
	//}

	public static byte[] Xor(byte[] clearTextBytes )
	{

		byte[] key = GenKey (clearTextBytes.Length);

		//Debug.Log ("KEY : " + Encoding.Unicode.GetString (key));

		MemoryStream ms = new MemoryStream();
	
		for (int i = 0; i < clearTextBytes.Length; i++) {

			byte b = (byte)(  (clearTextBytes [i] ^ key [i]) );

			//if (b == 0 ) {
			//	b = key [i];
				//Debug.Log ("GOt NULL BYTE FROM KEY: " + key [i] + ", BYTE: " + clearTextBytes [i]);
			//}

			ms.WriteByte ( b );
		}

		byte[] output =  ms.ToArray();
		//Debug.Log ("SCRAM OUT: " + output.Length);
		return output;

	}
开发者ID:unit9,项目名称:swip3,代码行数:31,代码来源:CEncryption.cs

示例11: AES_Encrypt

    public static byte[] AES_Encrypt(byte[] bytesToBeEncrypted, byte[] passwordBytes)
    {
        byte[] encryptedBytes = null;

        // Set your salt here, change it to meet your flavor:
        // The salt bytes must be at least 8 bytes.
        byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };

        using (MemoryStream ms = new MemoryStream())
        {
          using (RijndaelManaged AES = new RijndaelManaged())
          {
        AES.KeySize = 256;
        AES.BlockSize = 128;

        var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000);
        AES.Key = key.GetBytes(AES.KeySize / 8);
        AES.IV = key.GetBytes(AES.BlockSize / 8);

        AES.Mode = CipherMode.CBC;

        using (var cs = new CryptoStream(ms, AES.CreateEncryptor(), CryptoStreamMode.Write))
        {
          cs.Write(bytesToBeEncrypted, 0, bytesToBeEncrypted.Length);
          cs.Close();
        }
        encryptedBytes = ms.ToArray();
          }
        }

        return encryptedBytes;
        //end public byte[] AES_Encrypt
    }
开发者ID:JorgMU,项目名称:AES256,代码行数:33,代码来源:SimpleAES256.cs

示例12: WrappedMemoryStream

 public WrappedMemoryStream(bool canRead, bool canWrite, bool canSeek, byte[] data)
 {
     wrapped = data != null ? new MemoryStream(data) : new MemoryStream();
     _canWrite = canWrite;
     _canRead = canRead;
     _canSeek = canSeek;
 }
开发者ID:Rayislandstyle,项目名称:corefx,代码行数:7,代码来源:WrappedMemoryStream.cs

示例13: Load

 public static object Load(string saveTag)
 {
     string temp = PlayerPrefs.GetString (saveTag);
     if (temp == string.Empty) {return null;}
     MemoryStream memoryStream = new MemoryStream (System.Convert.FromBase64String (temp));
     return binaryFormatter.Deserialize(memoryStream);
 }
开发者ID:Rgallouet,项目名称:Blue-Star,代码行数:7,代码来源:PPSerialization.cs

示例14: Main

    public static int Main(string [] args)
    {
        if (args.Length < 2)
            return Usage ();

        Dictionary<string,object> targs = new Dictionary<string,object> ();

        Assembly asm = Assembly.LoadFrom (args [0]);
        Type template_type = asm.GetType (args [1]);

        for (int i = 2; i + 1 < args.Length; i += 2) {
            targs.Add (args [i], args [i + 1]);
        }

        targs ["test_enumerable"] = new List<string> () { "one", "two", "three", "four" };

        Console.WriteLine ("TEMPLATE TYPE:  {0}", template_type);
        MethodInfo meth = template_type.GetMethod ("RenderToStream");
        object template = Activator.CreateInstance (template_type);

        MemoryStream stream = new MemoryStream ();
        StreamWriter writer = new StreamWriter (stream);

        meth.Invoke (template, new object [] { Console.Out, targs });

        return 0;
    }
开发者ID:vbatz258,项目名称:manos,代码行数:27,代码来源:render.cs

示例15: Decrypt

    // Decrypt a byte array into a byte array using a key and an IV
    public static byte[] Decrypt(byte[] cipherData, byte[] Key, byte[] IV)
    {
        // Create a MemoryStream that is going to accept the decrypted bytes

        MemoryStream ms = new MemoryStream();

        // Create a symmetric algorithm.

        // We are going to use Rijndael because it is strong and available on all platforms.

        // You can use other algorithms, to do so substitute the next line with something like

        //                      TripleDES alg = TripleDES.Create();

        Rijndael alg = Rijndael.Create();

        // Now set the key and the IV.

        // We need the IV (Initialization Vector) because the algorithm is operating in its default

        // mode called CBC (Cipher Block Chaining). The IV is XORed with the first block (8 byte)

        // of the data after it is decrypted, and then each decrypted block is XORed with the previous

        // cipher block. This is done to make encryption more secure.

        // There is also a mode called ECB which does not need an IV, but it is much less secure.

        alg.Key = Key;

        alg.IV = IV;

        // Create a CryptoStream through which we are going to be pumping our data.

        // CryptoStreamMode.Write means that we are going to be writing data to the stream

        // and the output will be written in the MemoryStream we have provided.

        CryptoStream cs = new CryptoStream(ms, alg.CreateDecryptor(), CryptoStreamMode.Write);

        // Write the data and make it do the decryption

        cs.Write(cipherData, 0, cipherData.Length);

        // Close the crypto stream (or do FlushFinalBlock).

        // This will tell it that we have done our decryption and there is no more data coming in,

        // and it is now a good time to remove the padding and finalize the decryption process.

        cs.Close();

        // Now get the decrypted data from the MemoryStream.

        // Some people make a mistake of using GetBuffer() here, which is not the right way.

        byte[] decryptedData = ms.ToArray();

        return decryptedData;
    }
开发者ID:khaha2210,项目名称:CodeNewHis,代码行数:61,代码来源:EnDec.cs


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