Exemplo n.º 1
0
        // 放入数据
        private bool PushData(byte[] pushBuffer, Int32 bufOffset, Int32 pushLength, ENCRYPTOPT encryptOption)
        {
            if (Utilitys.GetTableEncrypt() == null)
            {
                return(false);
            }

            if (GetFreeSpaceLength() < pushLength)
            {
                return(false);
            }

            if (pushBuffer != null)
            {
                Int32 tailWriteSpace = GetTailWriteLength();
                if ((writePosition >= readPosition) && (tailWriteSpace < pushLength))
                {
                    Buffer.BlockCopy(pushBuffer, bufOffset, dataBuffer, writePosition, tailWriteSpace);

                    if (encryptOption == ENCRYPTOPT.codeEncrypt)
                    {
                        Utilitys.GetTableEncrypt().Encrypt(dataBuffer, writePosition, tailWriteSpace);
                    }
                    else if (encryptOption == ENCRYPTOPT.codeUnencrypt)
                    {
                        Utilitys.GetTableEncrypt().Unencrypt(dataBuffer, writePosition, tailWriteSpace);
                    }

                    Int32 leaveWriteLength = pushLength - tailWriteSpace;
                    Buffer.BlockCopy(pushBuffer, bufOffset + tailWriteSpace, dataBuffer, 0, leaveWriteLength);
                    if (encryptOption == ENCRYPTOPT.codeEncrypt)
                    {
                        Utilitys.GetTableEncrypt().Encrypt(dataBuffer, 0, leaveWriteLength);
                    }
                    else if (encryptOption == ENCRYPTOPT.codeUnencrypt)
                    {
                        Utilitys.GetTableEncrypt().Unencrypt(dataBuffer, 0, leaveWriteLength);
                    }

                    return(true);
                }
                else
                {
                    Buffer.BlockCopy(pushBuffer, bufOffset, dataBuffer, writePosition, pushLength);
                }
            }

            if (encryptOption == ENCRYPTOPT.codeEncrypt)
            {
                Utilitys.GetTableEncrypt().Encrypt(dataBuffer, writePosition, pushLength);
            }
            else if (encryptOption == ENCRYPTOPT.codeUnencrypt)
            {
                Utilitys.GetTableEncrypt().Unencrypt(dataBuffer, writePosition, pushLength);
            }

            return(true);
        }