Пример #1
0
        private void Encrypt()
        {
            if (string.IsNullOrWhiteSpace(UnencryptedBox.Text))
            {
                return;
            }

            Bitmap encryptedBitmap = BmpPwd.Encrypt("MyPassword", UnencryptedBox.Text, new Cipher(), scheme, colorScheme);

            //Convert Bitmap to ImageSource
            using (MemoryStream memory = new MemoryStream()) {
                encryptedBitmap.Save(memory, ImageFormat.Png);
                byte[] bytes = memory.ToArray();
                EncryptedImage.Source = ByteToImage(bytes);
            }
        }
Пример #2
0
        private void OpenButton_OnClick(object sender, RoutedEventArgs e)
        {
            try {
                string path;

                OpenFileDialog sfd = new OpenFileDialog();
                sfd.Filter           = "Image files (*.png)|*.png";
                sfd.FilterIndex      = 2;
                sfd.RestoreDirectory = true;

                if (sfd.ShowDialog() == true)
                {
                    path = sfd.FileName;

                    byte[] bytes = File.ReadAllBytes(path);

                    BitmapImage biImg = new BitmapImage();
                    using (MemoryStream ms = new MemoryStream(bytes)) {
                        biImg.BeginInit();
                        biImg.StreamSource = ms;
                        biImg.EndInit();

                        EncryptedImage.Source = biImg;

                        using (MemoryStream outStream = new MemoryStream()) {
                            BitmapEncoder enc = new BmpBitmapEncoder();
                            enc.Frames.Add(BitmapFrame.Create(biImg));
                            enc.Save(outStream);
                            Bitmap bitmap = new Bitmap(outStream);

                            DecryptedBox.Text = BmpPwd.Decrypt("MyPassword", new Bitmap(bitmap), new Cipher(), scheme, colorScheme);

                            MessageBox.Show("Decrypted: " + DecryptedBox.Text, "Successfully decrypted!");
                        }
                    }
                }
            } catch (Exception ex) {
                MessageBox.Show($"Could not open Image!\n{ex.Message}", "Error opening Image");
            }
        }
Пример #3
0
 //Text & Bitmap Decryption
 #region Decrypt
 /// <summary>
 /// Decrypt a encrypted <see cref="Bitmap"/> to a <see cref="string"/>
 /// </summary>
 /// <param name="salt">The salt used for the Encryption</param>
 /// <param name="encryptedBitmap">The <see cref="BmpPwd"/> Encrypted <see cref="Bitmap"/></param>
 /// <returns>The decrypted Text from the Bitmap</returns>
 public static string Decrypt(string salt, Bitmap encryptedBitmap)
 {
     return(BmpPwd.Decrypt(salt, encryptedBitmap, new Cipher(), DrawingScheme.Line));
 }
Пример #4
0
 //Text & Bitmap Encryption
 #region Encrypt
 /// <summary>
 /// Encrypt Text to a Bitmap with default Cipher Encryption
 /// </summary>
 /// <param name="salt">The salt used for the Encryption</param>
 /// <param name="unencryptedText">The original unencrypted Text</param>
 /// <returns>The Encrypted Bitmap</returns>
 public static Bitmap Encrypt(string salt, string unencryptedText)
 {
     return(BmpPwd.Encrypt(salt, unencryptedText, new Cipher()));
 }