public byte[] Sign(byte[] data) { Buf b = new Buf(data); b.SeekToEnd(); b.Write(keyData); return Secure.HashSHA1(b.ByteData); }
public Cert(Buf buf) { init(buf.ByteData); }
public CommonSign(Buf buf) { init(buf.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 RsaInner(Buf b) { init(b.ByteData); }
public void Build(string dstFileName) { Buf b = Build(); IO.SaveFile(dstFileName, b.ByteData); }
public void ReadToBuf(Buf buf, int size) { byte[] data = Read(size); buf.Write(data); }
void init(Buf data, Encoding encoding) { if (encoding == null) { encoding = defaultEncoding; } int bomSize = 0; Encoding enc2 = null; if (data != null) { enc2 = Str.CheckBOM(data.ByteData, out bomSize); } if (bomSize >= 1) { data = new Buf(Util.RemoveStartByteArray(data.ByteData, bomSize)); } if (enc2 != null) { encoding = enc2; } this.encoding = encoding; entryList = new List<CsvEntry>(); if (data != null) { MemoryStream ms = new MemoryStream(data.ByteData); StreamReader sr = new StreamReader(ms, this.encoding); while (true) { string s = sr.ReadLine(); if (s == null) { break; } char[] sep = { ',' }; string[] strings = s.Trim().Split(sep, StringSplitOptions.None); CsvEntry e = new CsvEntry(strings); Add(e); } } }
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; }
public Csv(Buf data) { byte[] src = data.ByteData; int bomSize; Encoding enc = Str.CheckBOM(src, out bomSize); if (bomSize >= 1) { src = Util.RemoveStartByteArray(src, bomSize); } init(new Buf(src), enc); }
public Csv(Buf data, Encoding encoding) { init(data, encoding); }
public void Write(Buf buf) { Write(buf.ByteData); }
public Buf ReadHamcore(string name) { if (name[0] == '|') { name = name.Substring(1); } if (name[0] == '/' || name[0] == '\\') { name = name.Substring(1); } string filename = name; filename = filename.Replace("/", "\\"); Buf b; if (this.disableReadRawFile == false) { try { b = Buf.ReadFromFile(HamcoreDirName + "\\" + filename); return(b); } catch { } } lock (list) { HamCoreEntry c; string key = filename.ToUpper(); b = null; if (list.ContainsKey(key)) { c = list[key]; if (c.Buffer != null) { b = new Buf(c.Buffer); b.SeekToBegin(); c.LastAccess = Time.Tick64; } else { if (hamcore_io.Seek(SeekOrigin.Begin, (int)c.Offset)) { byte[] data = hamcore_io.Read((int)c.SizeCompressed); int dstSize = (int)c.Size; byte[] buffer = ZLib.Uncompress(data, dstSize); c.Buffer = buffer; b = new Buf(buffer); b.SeekToBegin(); c.LastAccess = Time.Tick64; } } } long now = Time.Tick64; foreach (HamCoreEntry cc in list.Values) { if (cc.Buffer != null) { if (((cc.LastAccess + HamcoreCacheExpires) < now) || cc.FileName.StartsWith("Li", StringComparison.CurrentCultureIgnoreCase)) { cc.Buffer = null; } } } } return(b); }
public Rsa(Buf b) { init(b.ByteData); }
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; }
void init(byte[] data, string filename) { updated = false; lock (typeof(ReadIni)) { string[] lines; string srcstr; DateTime lastUpdate = new DateTime(0); if (filename != null) { lastUpdate = IO.GetLastWriteTimeUtc(filename); datas = IniCache.GetCache(filename, lastUpdate); } if (datas == null) { if (data == null) { try { data = Buf.ReadFromFile(filename).ByteData; } catch { data = new byte[0]; datas = IniCache.GetCache(filename, new DateTime()); } } if (datas == null) { datas = new Dictionary <string, string>(); Encoding currentEncoding = Str.Utf8Encoding; srcstr = currentEncoding.GetString(data); lines = Str.GetLines(srcstr); foreach (string s in lines) { string line = s.Trim(); if (Str.IsEmptyStr(line) == false) { if (line.StartsWith("#") == false && line.StartsWith("//") == false && line.StartsWith(";") == false) { string key, value; if (Str.GetKeyAndValue(line, out key, out value)) { key = key.ToUpper(); if (datas.ContainsKey(key) == false) { datas.Add(key, value); } else { int i; for (i = 1; ; i++) { string key2 = string.Format("{0}({1})", key, i).ToUpper(); if (datas.ContainsKey(key2) == false) { datas.Add(key2, value); break; } } } } } } } if (filename != null) { IniCache.AddCache(filename, lastUpdate, datas); } updated = true; } } } }