本文整理汇总了C#中MemoryStream类的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream类的具体用法?C# MemoryStream怎么用?C# MemoryStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MemoryStream类属于命名空间,在下文中一共展示了MemoryStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: Serialize
public override void Serialize(MemoryStream stream)
{
header.Serialize(stream);
System.Byte[] angle_min_bytes = BitConverter.GetBytes(angle_min);
stream.Write(angle_min_bytes, 0, angle_min_bytes.Length);
System.Byte[] angle_max_bytes = BitConverter.GetBytes(angle_max);
stream.Write(angle_max_bytes, 0, angle_max_bytes.Length);
System.Byte[] angle_increment_bytes = BitConverter.GetBytes(angle_increment);
stream.Write(angle_increment_bytes, 0, angle_increment_bytes.Length);
System.Byte[] time_increment_bytes = BitConverter.GetBytes(time_increment);
stream.Write(time_increment_bytes, 0, time_increment_bytes.Length);
System.Byte[] scan_time_bytes = BitConverter.GetBytes(scan_time);
stream.Write(scan_time_bytes, 0, scan_time_bytes.Length);
System.Byte[] range_min_bytes = BitConverter.GetBytes(range_min);
stream.Write(range_min_bytes, 0, range_min_bytes.Length);
System.Byte[] range_max_bytes = BitConverter.GetBytes(range_max);
stream.Write(range_max_bytes, 0, range_max_bytes.Length);
System.Byte[] ranges_len_bytes = BitConverter.GetBytes((System.UInt32)ranges.Count);
stream.Write(ranges_len_bytes, 0, ranges_len_bytes.Length);
foreach(sensor_msgs.LaserEcho element in ranges)
{
element.Serialize(stream);
}
System.Byte[] intensities_len_bytes = BitConverter.GetBytes((System.UInt32)intensities.Count);
stream.Write(intensities_len_bytes, 0, intensities_len_bytes.Length);
foreach(sensor_msgs.LaserEcho element in intensities)
{
element.Serialize(stream);
}
}
开发者ID:WPI-ARC,项目名称:kinect2_interface,代码行数:30,代码来源:MultiEchoLaserScan.cs
示例17: Serialize
public override void Serialize(MemoryStream stream)
{
header.Serialize(stream);
System.Byte[] height_bytes = BitConverter.GetBytes(height);
stream.Write(height_bytes, 0, height_bytes.Length);
System.Byte[] width_bytes = BitConverter.GetBytes(width);
stream.Write(width_bytes, 0, width_bytes.Length);
System.Byte[] fields_len_bytes = BitConverter.GetBytes((System.UInt32)fields.Count);
stream.Write(fields_len_bytes, 0, fields_len_bytes.Length);
foreach(sensor_msgs.PointField element in fields)
{
element.Serialize(stream);
}
System.Byte[] is_bigendian_bytes = BitConverter.GetBytes(is_bigendian);
stream.Write(is_bigendian_bytes, 0, is_bigendian_bytes.Length);
System.Byte[] point_step_bytes = BitConverter.GetBytes(point_step);
stream.Write(point_step_bytes, 0, point_step_bytes.Length);
System.Byte[] row_step_bytes = BitConverter.GetBytes(row_step);
stream.Write(row_step_bytes, 0, row_step_bytes.Length);
System.Byte[] compression_type_bytes = new System.Byte[] {compression_type};
stream.Write(compression_type_bytes, 0, compression_type_bytes.Length);
System.Byte[] compressed_data_bytes = compressed_data.ToArray();
System.Byte[] compressed_data_len_bytes = BitConverter.GetBytes((System.UInt32)compressed_data_bytes.Length);
stream.Write(compressed_data_len_bytes, 0, compressed_data_len_bytes.Length);
stream.Write(compressed_data_bytes, 0, compressed_data_bytes.Length);
System.Byte[] is_dense_bytes = BitConverter.GetBytes(is_dense);
stream.Write(is_dense_bytes, 0, is_dense_bytes.Length);
}
开发者ID:WPI-ARC,项目名称:kinect2_interface,代码行数:28,代码来源:CompressedPointCloud2.cs
示例18: GenerateMimeEncodedChunk
/// <summary>
/// Builds and in memory stream containing the binary data in a multi-part MIME that is ready for upload
/// </summary>
/// <returns></returns>
public override byte [] GenerateMimeEncodedChunk()
{
var inMemoryStream = new MemoryStream();
using (inMemoryStream)
{
WriteBoundaryLine(inMemoryStream);
// WriteAsciiLine(inMemoryStream, "Content-Disposition: name=\"request_payload\"");
WriteAsciiLine(inMemoryStream, "Content-Disposition: form-data; name=\"request_payload\""); //Server v9.2 is stricter about request syntax
WriteAsciiLine(inMemoryStream, "Content-Type: text/xml");
WriteAsciiLine(inMemoryStream);
WriteAsciiLine(inMemoryStream); //[2015-10-17] Extra line to meet expectations for 2 empty lines after content
WriteBoundaryLine(inMemoryStream);
// WriteAsciiLine(inMemoryStream, "Content-Disposition: name=\"tableau_file\"; filename=\"FILE-NAME\"");
WriteAsciiLine(inMemoryStream, "Content-Disposition: form-data; name=\"tableau_file\"; filename=\"FILE-NAME\""); //Server v9.2 is stricter about request syntax
WriteAsciiLine(inMemoryStream, "Content-Type: application/octet-stream");
WriteAsciiLine(inMemoryStream);
//Write the raw binary data
inMemoryStream.Write(_uploadData, 0, _numberBytes);
WriteAsciiLine(inMemoryStream);
WriteBoundaryLine(inMemoryStream, true);
//Go to the beginning
inMemoryStream.Seek(0, SeekOrigin.Begin);
return inMemoryStream.ToArray();
}
}
开发者ID:yaswanth369,项目名称:TabMigrate,代码行数:32,代码来源:MimeWriterFileUploadChunk.cs
示例19: Serialize
public static string Serialize(object obj)
{
MemoryStream memoryStream = new MemoryStream ();
binaryFormatter.Serialize (memoryStream, obj);
string serialized = System.Convert.ToBase64String (memoryStream.ToArray ());
return serialized;
}
开发者ID:RealFighter64,项目名称:Paradroid,代码行数:7,代码来源:SaveAndLoad.cs
示例20: GET_PRESTATIONS_GROUPE
public MemoryStream GET_PRESTATIONS_GROUPE(MemoryStream xml)
{
Dictionary<object, Object> param = null;
MemoryStream mresult = null;
bool demo = false;
List<PRESTATIONS_GROUPE> result = null;
OperationContext.Current.OperationCompleted += new EventHandler(delegate(object sender, EventArgs args)
{
if (mresult != null)
mresult.Dispose();
});
try
{
param = Serializer.READC<Dictionary<object, object>>(xml);
demo = ((param.Keys.Any(x => x.Equals("DEMO"))) && (param["DEMO"] != null)) ? Convert.ToBoolean(param["DEMO"]) : false;
using (var CONTEXT = new dbAbisEntities((!demo) ? CS : CS_DEMO))
{
result =
CONTEXT.EXECUTE_ENTITY_STORED_PROCEDURE<PRESTATIONS_GROUPE>("PRESTATIONS_GROUPEget", param, new List<string> { "DEMO" });
}
mresult = Serializer.WRITEC<List<PRESTATIONS_GROUPE>>(result);
return mresult;
}
catch (Exception ex)
{
throw new ApplicationException(String.Empty, ex);
}
}
开发者ID:abiswoippy,项目名称:CYS.SERVICE,代码行数:34,代码来源:SCYS_PREST.cs
注:本文中的MemoryStream类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论