// 書き出す public void WriteToBuf(Buf b, ValueType type) { switch (type) { case ValueType.Int: b.WriteInt(IntValue); break; case ValueType.Int64: b.WriteInt64(Int64Value); break; case ValueType.Data: b.WriteInt((uint)Data.Length); b.Write(Data); break; case ValueType.Str: b.WriteStr(StrValue.Trim()); break; case ValueType.UniStr: byte[] data = Str.Utf8Encoding.GetBytes(StrValue.Trim()); b.WriteInt((uint)data.Length + 1); b.Write(data); b.WriteByte(0); break; } }
// ファイルに書き込み (ハッシュ付ける) public void WriteToFileWithHash(string filename) { byte[] data = this.ByteData; byte[] hash = Secure.HashSHA1(data); Buf b = new Buf(); b.Write(hash); b.Write(data); b.WriteToFile(filename); }
public static void AddDataEntry(Buf buf, string entryName, string str) { byte[] entryNameByte = GenerateEntryName(entryName); buf.Write(entryNameByte); string numStr = str.Length.ToString("0000000000"); buf.Write(Str.AsciiEncoding.GetBytes(numStr)); buf.Write(Str.AsciiEncoding.GetBytes(str)); }
public Buf ToBuf() { string s = ToString(); Buf b = new Buf(); byte[] bom = Str.GetBOM(this.Encoding); if (bom != null) { b.Write(bom); } b.Write(encoding.GetBytes(s)); b.SeekToBegin(); return(b); }
// PKCS パディング public static byte[] PkcsPadding(byte[] srcData, int destSize) { int srcSize = srcData.Length; if ((srcSize + 11) > destSize) { throw new OverflowException(); } int randSize = destSize - srcSize - 3; byte[] rand = Secure.Rand((uint)randSize); Buf b = new Buf(); b.WriteByte(0x00); b.WriteByte(0x02); b.Write(rand); b.WriteByte(0x00); b.Write(srcData); return(b.ByteData); }
// ストリームからすべて読み出す public static byte[] ReadAllFromStream(Stream st) { byte[] tmp = new byte[32 * 1024]; Buf b = new Buf(); while (true) { int r = st.Read(tmp, 0, tmp.Length); if (r == 0) { break; } b.Write(tmp, 0, r); } return(b.ByteData); }
// ストリームから読み込み public static Buf ReadFromStream(Stream st) { Buf ret = new Buf(); int size = 32767; while (true) { byte[] tmp = new byte[size]; int i = st.Read(tmp, 0, tmp.Length); if (i <= 0) { break; } Array.Resize <byte>(ref tmp, i); ret.Write(tmp); } ret.SeekToBegin(); return(ret); }
public Buf SaveToBuf() { Buf b = new Buf(); b.WriteInt64((ulong)this.TimeStamp.Ticks); b.WriteInt((uint)this.EntryList.Count); foreach (FullRouteIPInfoEntry e in this.EntryList) { b.WriteInt(e.From); b.WriteInt(e.To); b.WriteStr(e.Registry); b.WriteInt(e.Assigned); b.WriteStr(e.Country2); b.WriteStr(e.Country3); b.WriteStr(e.CountryFull); } b.Write(Secure.HashSHA1(b.ByteData)); b.SeekToBegin(); return(b); }
public void ReadToBuf(Buf buf, int size) { byte[] data = Read(size); buf.Write(data); }