Esempio n. 1
0
        /// <summary>
        /// Create a new Header decoder
        /// </summary>
        /// <param name="input">The byte array extracted from the image</param>
        /// <param name="key">The key used to initially encrypt the data</param>
        public TP_Header(byte[] input, string key)
        {
            Key = key;

            // The header is 144 bytes encrypted, but only 128 bytes decrypted
            if (input.Length > 144)
            {
                // Get just the bytes for the header from the data
                byte[] headerPre = new byte[144];
                for (int i = 0; i < headerPre.Length; i++)
                {
                    headerPre[i] = input[i];
                }

                // Decrypt the header
                byte[] header = TP_Encrypt.Decrypt(headerPre, key);

                // See if the decrypted header is actually a header
                // If IsValid is true, then the image most likely contains a hidden file
                // There is only a 1 in 2^24 chance (about 0.00000006%) that this will falsely be true
                IsValid = header[header.Length - 3] == TP_File.SIGNATURE[0] &&
                          header[header.Length - 2] == TP_File.SIGNATURE[1] &&
                          header[header.Length - 1] == TP_File.SIGNATURE[2];

                if (IsValid)
                {
                    // Get the length of the hidden file
                    FileLength  = 0;
                    FileLength |= header[0] << 24;
                    FileLength |= header[1] << 16;
                    FileLength |= header[2] << 8;
                    FileLength |= header[3];

                    // Get the length of the file name
                    int length = (int)header[4];
                    FileName = "";

                    // Get the original file name
                    for (int i = 0; i < length; i++)
                    {
                        FileName += (char)header[i + 5];
                    }
                }
            }
            else
            {
                IsValid = false;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Save the file represented by this data object.
        /// </summary>
        /// <param name="location">The location to save the file.</param>
        public void Save(string location)
        {
            byte[] data = GetFileBytes();

            File.WriteAllBytes(location, TP_Encrypt.Decrypt(data, fileHeader.Key));
        }