예제 #1
0
        /// <summary>
        /// This function decode and extract the payload from an image
        /// </summary>
        /// <param name="ImageFileName">Image File Name</param>
        /// <param name="OriginalFileName">returns the Decoded Payload File Name</param>
        /// <param name="passphrase">Passphrase for data decryption</param>
        /// <param name="hash">return the file hash</param>
        /// <returns>Payload data</returns>
        static public byte[] Decode(string ImageFileName, ref string OriginalFileName, string passphrase, ref byte[] hash)
        {
            PayloadFile payload = new PayloadFile();
            Bitmap      Image   = new Bitmap(ImageFileName);

            payload          = GetPayloadFromImage(Image, passphrase);
            OriginalFileName = payload.Filename;
            hash             = payload.hash;
            return(payload.data);
        }
예제 #2
0
        /// <summary>
        /// This Function extract a Payload Data from an RGB Image
        /// </summary>
        /// <param name="Image">RGB Image Data</param>
        /// <param name="passphrase">Passphrase to decrypt data</param>
        /// <returns></returns>
        static PayloadFile GetPayloadFromImage(Bitmap Image, string passphrase)
        {
            int height = Image.Height;
            int width  = Image.Width;

            PayloadFile payload = new PayloadFile();

            MemoryStream str = new MemoryStream();

            for (int i = 0; i < height; i++)
            {
                for (int j = 0; j < width; j++)
                {
                    Int32 pixel = Image.GetPixel(j, i).ToArgb();
                    str.WriteByte(GetByteFromPixel(pixel));
                }
            }

            if (passphrase != "")
            {
                byte[] cipherByte       = str.ToArray();
                int    cipherTextLength = (cipherByte.Length - 32) / 16;

                cipherTextLength = (cipherTextLength + 1) * 16;

                Array.Resize(ref cipherByte, cipherTextLength);

                str = new MemoryStream(Crypto.Decrypt(cipherByte, passphrase));
            }

            str.Seek(0, SeekOrigin.Begin);
            byte[] temp = new byte[4];
            str.Read(temp, 0, 4);
            UInt32 FileSize = BitConverter.ToUInt32(temp, 0);

            str.Read(temp, 0, 4);
            UInt32 FileNameLen = BitConverter.ToUInt32(temp, 0);

            byte[] buffer = new byte[FileNameLen];
            str.Read(buffer, 0, (int)FileNameLen);

            payload.Filename = System.Text.ASCIIEncoding.ASCII.GetString(buffer);
            payload.data     = new byte[FileSize];

            str.Read(payload.data, 0, (int)FileSize);

            payload.hash = new byte[32];
            str.Read(payload.hash, 0, 32);

            str.Close();

            return(payload);
        }