示例#1
0
        public unsafe byte[] Decoder(string str)
        {
            if (string.IsNullOrWhiteSpace(str) || str.Length % 4 != 0)
            {
                return(null);
            }


            byte[] Source = null;

            try
            {
                Source = MyBase64.FromBase64String(str);
            }
            catch
            {
                return(null);
            }

            if (Source == null)
            {
                return(null);
            }

            var sizeSortie = Source.Length - (Complement + SizeCrc + SizeKey);

            if (sizeSortie <= 0)
            {
                return(null);
            }

            Byte[] DecSource = new Byte[sizeSortie];

            fixed(byte *outdate = DecSource)
            {
                fixed(byte *inData = Source)
                {
                    if (!Decode(inData, Source.Length, outdate, sizeSortie))
                    {
                        return(null);
                    }
                }
            }

            byte EndFlag = (byte)(byte.MaxValue ^ (byte)DecSource[0]); //.FirstOrDefault()

            if (EndFlag > DecSource.Length)
            {
                return(null);
            }

            int count = DecSource.Length - (1 + EndFlag);

            byte[] dtime  = new byte[EndFlag];
            byte[] Sortie = new byte[count];

            fixed(byte *outSortie = Sortie)
            {
                fixed(byte *outdtime = dtime)
                {
                    fixed(byte *inData = DecSource)
                    {
                        Filtre(inData, DecSource.Length, outSortie, count, outdtime, EndFlag);
                    }
                }
            }

            if (EndFlag == 8)
            {
                DateTime d = DateTime.FromBinary(BitConverter.ToInt64(dtime, 0));
            }

            return(Sortie);
        }
示例#2
0
        public unsafe string Encoder(byte[] Source)
        {
            if (Source == null)
            {
                return(null);
            }

            byte idx;

            switch (Shift)
            {
            case 0:
                idx = (byte)(DateTime.UtcNow.Millisecond % byte.MaxValue);
                break;

            case 1:
                idx = (byte)(DateTime.UtcNow.Second % byte.MaxValue);
                break;

            case 2:
                idx = (byte)(DateTime.UtcNow.Minute % byte.MaxValue);
                break;

            case 3:
                idx = (byte)(DateTime.UtcNow.Hour % byte.MaxValue);
                break;

            case 5:
                idx = (byte)(DateTime.UtcNow.Day % byte.MaxValue);
                break;

            case 6:
                idx = (byte)(DateTime.UtcNow.Month % byte.MaxValue);
                break;

            case 7:
                idx = (byte)(DateTime.UtcNow.Year % byte.MaxValue);
                break;

            default:
                idx = (byte)(DateTime.UtcNow.Day % byte.MaxValue);
                break;
            }


            byte[] bFlag;
            byte   EndFlag;

            if (TimeStamp)
            {
                bFlag   = BitConverter.GetBytes(DateTime.Now.Ticks);
                EndFlag = (byte)(bFlag.Length);
            }
            else
            {
                bFlag   = new byte[1];
                EndFlag = 0;
            }

            int newtaille = Source.Length + EndFlag + 1 + Complement + SizeCrc + SizeKey;

            byte[] ArrSource = new byte[newtaille];

            fixed(byte *InData1 = new byte[] { (byte)(byte.MaxValue - EndFlag) })
            {
                fixed(byte *InData2 = bFlag)
                {
                    fixed(byte *InData3 = Source)
                    {
                        fixed(byte *outData = ArrSource)
                        {
                            byte *[] Inff  = { InData1, InData2, InData3 };
                            byte *[] endff = { InData1 + 1 - 1, InData2 + EndFlag - 1, InData3 + Source.Length - 1 };

                            Encode(outData, newtaille, Inff, endff, 3, idx);
                        }
                    }
                }
            }

            return(MyBase64.ToBase64String(ArrSource));
        }