private void BtnCheck_Click(object sender, RoutedEventArgs e) { if (Signa.KeysArePresent()) { try { FileStream fsImatge = new FileStream(imatge, FileMode.Open, FileAccess.Read); FileStream fsSignatura = new FileStream(signatura, FileMode.Open, FileAccess.Read); string messageBoxText, caption; if (Signa.ValidateSignature(fsImatge, fsSignatura)) { messageBoxText = "La signatura és correcta."; caption = "Signatura Correcta"; } else { messageBoxText = "La signatura no és correcta."; caption = "Signatura Incorrecta"; } MessageBoxButton button = MessageBoxButton.OK; MessageBoxImage icon = MessageBoxImage.None; MessageBoxResult result = MessageBox.Show(messageBoxText, caption, button, icon); } catch (FileNotFoundException) { if (!File.Exists(imatge)) { MessageBoxImageNotFound(); } if (!File.Exists(signatura)) { MessageBoxSignatureNotFound(); } } catch (ArgumentNullException) { if (!File.Exists(imatge)) { MessageBoxImageNotFound(); } if (!File.Exists(signatura)) { MessageBoxSignatureNotFound(); } } } else { MessageBoxKeyNotFound(); } }
private void BtnSign_Click(object sender, RoutedEventArgs e) { if (!Signa.KeysArePresent()) { MessageBoxKeyNotFound(); } else { try { FileStream fsImatge = new FileStream(imatge, FileMode.Open, FileAccess.Read); var dialog = new System.Windows.Forms.FolderBrowserDialog(); dialog.Description = "Selecciona la carpeta on es desarà la signatura."; System.Windows.Forms.DialogResult res = dialog.ShowDialog(); if (res == System.Windows.Forms.DialogResult.OK) { string path = dialog.SelectedPath; Signa.Sign(fsImatge, path); string messageBoxText = "Imatge signada correctament."; string caption = "Signatura completada"; MessageBoxButton button = MessageBoxButton.OK; MessageBoxImage icon = MessageBoxImage.None; MessageBoxResult result = MessageBox.Show(messageBoxText, caption, button, icon); } fsImatge.Close(); } catch (FileNotFoundException) { MessageBoxImageNotFound(); } catch (ArgumentNullException) { MessageBoxImageNotFound(); } } }