Esempio n. 1
0
 public async Task Decrypt(string filename, int seed, int bits)
 {
     await WaitDialogHelper.ExecuteThreadAsync("Decrypt Image",
                                               () => DecryptText = Interface.Decrypt((BitmapImage)ImageSource, ChannelUsage.Default, seed), exception =>
     {
         if (exception != null)
         {
             ErrorHelper.Add(3, exception.Message, exception.StackTrace);
         }
     });
 }
Esempio n. 2
0
        /// <summary>
        /// Encrypts a text to a picture and saves it
        /// </summary>
        /// <param name="openFilePath">Path from were the picture gets loaded</param>
        /// <param name="encryptText">The text which gets hidden in the picture</param>
        /// <param name="seed"></param>
        /// <param name="bits"></param>
        public async Task Encrypt(string openFilePath, string encryptText, int seed, int bits)
        {
            await WaitDialogHelper.ExecuteThreadAsync("Encrypt Message", () =>
            {
                string saveFilePath = RuntimeGlobals.ShowSaveFileDialog("PNG Image (*.png)|*.png", RuntimeGlobals.Settings.SavePath);

                if (string.IsNullOrEmpty(saveFilePath))
                {
                    return;
                }
                if (!InputOutput.CheckPathIsValidImage(saveFilePath))
                {
                    throw new FileFormatException();
                }
                if (saveFilePath.Equals(openFilePath))
                {
                    throw new FileLoadException();
                }

                var image = Interface.Encrypt((BitmapImage)ImageSource, ChannelUsage.Default, seed, encryptText);
                InputOutput.SaveImageToFile(saveFilePath, image);
                GC.Collect();
            }, exception =>
            {
                if (exception != null)
                {
                    if (exception is OutOfMemoryException)
                    {
                        ErrorHelper.Add(6, exception.Message, exception.StackTrace);
                    }
                    else if (exception is FileFormatException)
                    {
                        ErrorHelper.Add(4);
                    }
                    else if (exception is FileLoadException)
                    {
                        ErrorHelper.Add(5);
                    }
                    else
                    {
                        ErrorHelper.Add(3, exception.GetType() + "\n" + exception.Message, exception.StackTrace);
                    }
                }
            });
        }