예제 #1
0
 public void SetFileInfo(EncryptionFileInfo fileInfo)
 {
     EncFileInfo = fileInfo;
 }
예제 #2
0
        public bool MakeEncArgv(ref byte[] rawData, ref EncryptionArgv encArgv)
        {
            // Get Header size and Data size
            EncryptionFileInfo efi = new EncryptionFileInfo();

            byte[] headerSizeBytes = new byte[4];
            byte[] dataSizeBytes   = new byte[8];
            Buffer.BlockCopy(rawData, 4, headerSizeBytes, 0, 4);
            Buffer.BlockCopy(rawData, 8, dataSizeBytes, 0, 8);
            int  headerSize = BitConverter.ToInt32(headerSizeBytes, 0);
            long dataSizeL  = BitConverter.ToInt64(dataSizeBytes, 0);

            if (int.MaxValue < dataSizeL)
            {
                return(false);
            }
            int dataSize = (int)dataSizeL;

            byte[] headerRawBytes = new byte[headerSize];
            efi.FileData = new byte[dataSize];
            Buffer.BlockCopy(rawData, 80, headerRawBytes, 0, headerRawBytes.Length);
            Buffer.BlockCopy(rawData, 80 + headerRawBytes.Length, efi.FileData, 0, efi.FileData.Length);

            // Decrypt header data
            byte[] headerBytes = Chipher.Aes.DecryptData(ref headerRawBytes, encArgv.PrivatePassword, MakeDefaultAes());
            headerRawBytes = null;

            // Read binary header data
            efi.IsAesMode = BitConverter.ToBoolean(headerBytes, 0);
            if (efi.IsAesMode)
            {
                encArgv.AesInfo.Mode      = (CipherMode)(int)headerBytes[1];
                encArgv.AesInfo.BlockSize = (int)headerBytes[2] + 1;
                encArgv.AesInfo.KeySize   = (int)headerBytes[3] + 1;
                encArgv.AesInfo.Padding   = (PaddingMode)(int)headerBytes[4];
            }
            efi.IsCompressedZipFile = BitConverter.ToBoolean(headerBytes, 5);

            efi.FileNotContentIndexed = BitConverter.ToBoolean(headerBytes, 10);
            efi.FileOffline           = BitConverter.ToBoolean(headerBytes, 11);
            efi.FileReadOnly          = BitConverter.ToBoolean(headerBytes, 12);
            efi.FileHidden            = BitConverter.ToBoolean(headerBytes, 13);
            efi.FileArchive           = BitConverter.ToBoolean(headerBytes, 14);
            efi.FileSystem            = BitConverter.ToBoolean(headerBytes, 15);
            Buffer.BlockCopy(headerBytes, 16, efi.MD5FileHash, 0, efi.MD5FileHash.Length);

            // Read string header data
            byte[] strHeaderRaw = new byte[headerBytes.Length - 32];
            Buffer.BlockCopy(headerBytes, 32, strHeaderRaw, 0, strHeaderRaw.Length);
            string[] strHeader = Encoding.UTF8.GetString(strHeaderRaw).Split('|');

            efi.FilePath                 = strHeader[0];
            efi.FileName                 = Path.GetFileName(strHeader[0]);
            efi.FileExtension            = Path.GetExtension(strHeader[0]);
            efi.FileNameWithoutExtension = Path.GetFileNameWithoutExtension(strHeader[0]);
            efi.FileDirectory            = Path.GetDirectoryName(strHeader[0]);

            efi.CreationTime   = DateTime.Parse(strHeader[1]);
            efi.LastWriteTime  = DateTime.Parse(strHeader[2]);
            efi.LastAccessTime = DateTime.Parse(strHeader[3]);

            encArgv.SetFileInfo(efi);
            return(true);
        }