Ejemplo n.º 1
0
 public void TestFile() {
    File file = new File("..");
    FileTransform format = new FileTransform();
    String value = format.write(file);
    File copy = format.read(value);
    AssertEquals(file, copy);
 }
Ejemplo n.º 2
0
        public void ExecuteRetrieveFile(object args)
        {
            try
            {
                var deHideOption = this.GetDeHideOptionFromView((Window)args);

                if (deHideOption == null)
                {
                    return;
                }

                var ciphertext = HideLSB.DeHide(this._hiddenImageBitmapCache);

                IEncryption encryptor = EncryptionFactory.CreateEncryption(deHideOption.EncryptionAlg);
                var         plaintext = encryptor.Decrypt(ciphertext, this.StrPassword2UintArr(deHideOption.Password));
                var         deZipdata = Zip.Decompress(plaintext);

                if (File.Exists(deHideOption.FilePath))
                {
                    File.Delete(deHideOption.FilePath);
                }

                FileTransform.ByteArray2File(deHideOption.FilePath, deZipdata);

                this.ShowMessageBoxResource("RetrieveDone", "Hint", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (PasswordWrongException)
            {
                this.ShowMessageBoxResource("PasswordWrong", "Error");
            }
            catch (Exception)
            {
                this.ShowMessageBoxResource("PasswordWrong", "Error");
            }
        }
Ejemplo n.º 3
0
        public void CompressTest()
        {
            string srcFilePath = PathHelper.GetFilePath(@"/Data/mountain.bmp");

            var expected = FileTransform.File2ByteArray(srcFilePath);

            var zipedSrcFileBytes = Zip.Compress(expected);

            var actual = Zip.Decompress(zipedSrcFileBytes);

            CollectionAssert.AreEqual(actual, expected);
        }
Ejemplo n.º 4
0
        public void HideTest1()
        {
            string file          = PathHelper.GetFilePath(@"\Data\testDocx.docx");
            string coverImageUri = PathHelper.GetFilePath(@"\Data\boy.bmp");
            Bitmap imgTohide     = new Bitmap(coverImageUri);

            var expected = FileTransform.File2ByteArray(file);

            HideLSB.Hide(ref imgTohide, expected);
            byte[] actual = HideLSB.DeHide(imgTohide);

            CollectionAssert.AreEqual(expected, actual);
        }
Ejemplo n.º 5
0
        public void ExecuteEraseFile()
        {
            HideLSB.Erase(ref this._hiddenImageBitmapCache);
            this.HiddenImage = FileTransform.Bitmap2BitmapImage(this._hiddenImageBitmapCache);

            if (File.Exists(this.ImageFilePath))
            {
                File.Delete(this.ImageFilePath);
            }

            this._hiddenImageBitmapCache.Save(this.ImageFilePath);

            this.ShowMessageBoxResource("RetrieveDone", "Hint", MessageBoxButton.OK, MessageBoxImage.Information);
        }
Ejemplo n.º 6
0
        public void WriteFileBodyTest1()
        {
            string dataPath = PathHelper.GetFilePath(@"\Data\testPng.png");

            byte[] bytesExpect = FileTransform.File2ByteArray(dataPath);

            string imagePath = PathHelper.GetFilePath(@"\Data\boy.bmp");
            Bitmap image     = new Bitmap(imagePath);

            HideLSB.WriteFileBody(ref image, bytesExpect, 0, 0);
            byte[] bytesActual = HideLSB.ReadFileBody(image, bytesExpect.Length * 8, 0, 0);

            CollectionAssert.AreEqual(bytesExpect, bytesActual);
        }
Ejemplo n.º 7
0
        public void File2ByteArrayTest()
        {
            string srcPath = PathHelper.GetFilePath(@"/Data/testDocx.docx");
            string outPath = PathHelper.GetFilePath("/Data/testDocx_out.docx");

            var expected = FileTransform.File2ByteArray(srcPath);

            FileTransform.ByteArray2File(outPath, expected);

            var actual = FileTransform.File2ByteArray(outPath);

            File.Delete(outPath);

            CollectionAssert.AreEqual(expected, actual);
        }
Ejemplo n.º 8
0
        public void ExecuteOpenFile(object args)
        {
            try
            {
                var fileTypesPattern = "bmp file (*.bmp)|*.bmp|All files (*.*)|*.*";
                var defaultExt       = "bmp";
                var imageUri         = GetFilePathFromFileDialog.GetFilePathFromOpenFileDialog(fileTypesPattern, defaultExt);

                if (string.IsNullOrEmpty(imageUri))
                {
                    return;
                }

                var bitmapImg   = FileTransform.ImageUri2BitmapImage(imageUri);
                var bitmapCache = FileTransform.BitmapImage2Bitmap(bitmapImg);

                var openCmdPara = (string)args;
                if ("Cover".Equals(openCmdPara))
                {
                    this.CoverImage              = bitmapImg;
                    this._coverImageBitmapCache  = bitmapCache;
                    this.HiddenImage             = null;
                    this._hiddenImageBitmapCache = null;
                }
                else if ("Hidden".Equals(openCmdPara))
                {
                    this.HiddenImage             = bitmapImg;
                    this._hiddenImageBitmapCache = bitmapCache;
                    this.CoverImage             = null;
                    this._coverImageBitmapCache = null;
                }

                this.ImageFilePath = imageUri;
            }
            catch (FileFormatException)
            {
                this.ShowMessageBoxResource("MustBeBmpFile", "Hint");
            }
            catch (Exception)
            {
                this.ShowMessageBoxResource("MustBeBmpFile", "Hint");
            }
        }
Ejemplo n.º 9
0
        public void ExecuteHideFile(object args)
        {
            try
            {
                var hideOption = this.GetHideOptionFromView((Window)args);

                if (hideOption == null)
                {
                    return;
                }

                var fileBytesToHide      = FileTransform.File2ByteArray(hideOption.FilePath);
                var zipedCoverImageBytes = Zip.Compress(fileBytesToHide);

                IEncryption encryptor = EncryptionFactory.CreateEncryption(hideOption.EncryptionAlg);

                var ciphertext = encryptor.Encrypt(zipedCoverImageBytes, this.StrPassword2UintArr(hideOption.Password));

                var tmpBitmapCacheToHide =
                    this._coverImageBitmapCache.Clone(
                        new Rectangle(0, 0, this._coverImageBitmapCache.Width, this._coverImageBitmapCache.Height),
                        this._coverImageBitmapCache.PixelFormat);

                HideLSB.Hide(ref tmpBitmapCacheToHide, ciphertext);

                this._hiddenImageBitmapCache = tmpBitmapCacheToHide;
                this.HiddenImage             = FileTransform.Bitmap2BitmapImage(this._hiddenImageBitmapCache);
            }
            catch (ImageHideCapacityTooSmallException)
            {
                this.ShowMessageBoxResource("HidingCapacityNotEnough", "Hint", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            catch (IOException)
            {
                this.ShowMessageBoxResource("FileOpenError", "Error");
            }
            catch (Exception)
            {
                this.ShowMessageBoxResource("UnknownError", "Error");
            }
        }
Ejemplo n.º 10
0
 static void Main(string[] args)
 {
     FileToImage.FileTransform a = new FileTransform();
     //a.ExcelToJPG("");
     a.WordToJPG("");
 }