From 490a8d1b04f9f91e86b126a8da21de6e6cc047dd Mon Sep 17 00:00:00 2001 From: Tim Young Date: Wed, 9 Aug 2017 15:52:31 -0500 Subject: [PATCH] Throw a better error when we try and fail to load something. --- .../TrippleDESDocumentEncryption.cs | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/EduNetworkBuilder/TrippleDESDocumentEncryption.cs b/EduNetworkBuilder/TrippleDESDocumentEncryption.cs index 790a851..e0f02fb 100644 --- a/EduNetworkBuilder/TrippleDESDocumentEncryption.cs +++ b/EduNetworkBuilder/TrippleDESDocumentEncryption.cs @@ -128,10 +128,19 @@ namespace EduNetworkBuilder EncryptedXml exml = new EncryptedXml(); // Decrypt the element using the symmetric key. - byte[] rgbOutput = exml.DecryptData(ed, algValue); + try + { + //Do the decryption + byte[] rgbOutput = exml.DecryptData(ed, algValue); + // Replace the encryptedData element with the plaintext XML elemnt. + exml.ReplaceData(encryptedElement, rgbOutput); + } + catch + { + //The decryption failed. + throw new LoginException("Key/Salt unable to decrypt."); + } - // Replace the encryptedData element with the plaintext XML elemnt. - exml.ReplaceData(encryptedElement, rgbOutput); } @@ -186,4 +195,19 @@ namespace EduNetworkBuilder } } + + /// + /// Create a simple login exception that we can throw when we try to decrypt and it fails + /// + public class LoginException : System.Exception + { + public LoginException() : base() + { } + + public LoginException(String message) : base(message) + { } + + public LoginException(String message, Exception innerException) : base(message, innerException) + { } + } }