示例#1
0
        private bool DecryptFile(string inputFile, string outputFile)
        {
            byte[] srcData = mFileHandle.FileRead(inputFile);
            byte[] tmp     = new byte[XXTEA_sign.Length];
            if (srcData.Length < XXTEA_sign.Length)
            {
                return(false);
            }
            Array.Copy(srcData, tmp, XXTEA_sign.Length);
            for (int i = 0; i < XXTEA_sign.Length; i++)
            {
                if (tmp[i] != XXTEA_sign[i])
                {
                    richTextBox_log.AppendText("签名错误--->" + inputFile + "\n");
                    return(false);
                }
            }
            //此处需要去掉文件头的签名值并重新计算数据长度
            uint ret_length;
            int  len = srcData.Length - XXTEA_sign.Length;

            byte[] data = new byte[len];
            Buffer.BlockCopy(srcData, XXTEA_sign.Length, data, 0, len);
            byte[] data2 = mXXTEAHelp.xxtea_decrypt(data, (uint)len, XXTEA_KEY, (uint)XXTEA_KEY.Length, out ret_length);
            if (mFileHandle.FileWrite(data2, outputFile))
            {
                return(true);
            }
            return(false);
        }