From 4fe144c8b1105c53b3a39073c6072f538b9e39ca Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Thu, 26 Nov 2020 12:35:36 +0100 Subject: [PATCH] raise events on error --- Pilz.Cryptography/AESStringCrypter.cs | 9 +++++++-- Pilz.Cryptography/Pilz.Cryptography.csproj | 3 +++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Pilz.Cryptography/AESStringCrypter.cs b/Pilz.Cryptography/AESStringCrypter.cs index 54afc8c..4f66c01 100644 --- a/Pilz.Cryptography/AESStringCrypter.cs +++ b/Pilz.Cryptography/AESStringCrypter.cs @@ -9,6 +9,7 @@ namespace Pilz.Cryptography public class AESStringCrypter : ICrypter { public delegate void AESStringCrypterEventHandler(AESStringCrypter sender); + public delegate void AESStringCrypterErrorEventHandler(AESStringCrypter sender, Exception exception); /// /// This event throws if no key and no default key was found. You can now provide a key or default key (maybe depending on the given instance). If no value is provided, a default key will be created. @@ -18,6 +19,8 @@ namespace Pilz.Cryptography /// This event throws if no IV and no default IV was found. You can now provide a IV or default IV (maybe depending on the given instance). If no value is provided, a default IV will be created. /// public static event AESStringCrypterEventHandler NeedIV; + public static event AESStringCrypterErrorEventHandler ErrorAtDecrypting; + public static event AESStringCrypterErrorEventHandler ErrorAtEncrypting; private byte[] key = new byte[] { }; private byte[] iv = new byte[] { }; @@ -69,8 +72,9 @@ namespace Pilz.Cryptography { return DecryptStringFromBytes_Aes(Convert.FromBase64String(encryptedValue), GetKey(), GetIV()); } - catch (CryptographicException) + catch (Exception ex) { + ErrorAtDecrypting?.Invoke(this, ex); return string.Empty; } } @@ -87,8 +91,9 @@ namespace Pilz.Cryptography { return Convert.ToBase64String(EncryptStringToBytes_Aes(plainValue, GetKey(), GetIV())); } - catch (CryptographicException) + catch (Exception ex) { + ErrorAtEncrypting?.Invoke(this, ex); return string.Empty; } } diff --git a/Pilz.Cryptography/Pilz.Cryptography.csproj b/Pilz.Cryptography/Pilz.Cryptography.csproj index 6d5344e..d097b9d 100644 --- a/Pilz.Cryptography/Pilz.Cryptography.csproj +++ b/Pilz.Cryptography/Pilz.Cryptography.csproj @@ -5,6 +5,9 @@ Pilz.Cryptography Copyright © 2020 + + D:\repos\Pilz\Pilz.Cryptography\Pilz.Cryptography.xml +