示例#1
0
        public byte[] Sign(byte[] data)
        {
            Buf b = new Buf(data);
            b.SeekToEnd();
            b.Write(keyData);

            return Secure.HashSHA1(b.ByteData);
        }
示例#2
0
 public Cert(Buf buf)
 {
     init(buf.ByteData);
 }
示例#3
0
 public CommonSign(Buf buf)
 {
     init(buf.ByteData);
 }
示例#4
0
		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;
		}
示例#5
0
 public RsaInner(Buf b)
 {
     init(b.ByteData);
 }
示例#6
0
        public void Build(string dstFileName)
        {
            Buf b = Build();

            IO.SaveFile(dstFileName, b.ByteData);
        }
示例#7
0
		public void ReadToBuf(Buf buf, int size)
		{
			byte[] data = Read(size);

			buf.Write(data);
		}
示例#8
0
		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);
				}
			}
		}
示例#9
0
		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;
		}
示例#10
0
		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);
		}
示例#11
0
		public Csv(Buf data, Encoding encoding)
		{
			init(data, encoding);
		}
示例#12
0
        public void ReadToBuf(Buf buf, int size)
        {
            byte[] data = Read(size);

            buf.Write(data);
        }
示例#13
0
 public void Write(Buf buf)
 {
     Write(buf.ByteData);
 }
示例#14
0
        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);
        }
示例#15
0
 public Rsa(Buf b)
 {
     init(b.ByteData);
 }
示例#16
0
		public void Write(Buf buf)
		{
			Write(buf.ByteData);
		}
示例#17
0
        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;
        }
示例#18
0
        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;
                    }
                }
            }
        }