raise events on error
This commit is contained in:
@@ -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);
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user