private void HDecode(object sender, EventArgs e) { try { if (IsPasswordEnabled) { Impersonate(true); } var ct = Ciphertext.Value; if (ct.XIsBlank() && !Setting.Value.XIsBlank()) { try { var xml = MXml.LoadText(Setting); ct = xml.X("value"); } catch { throw MException.MessageException("Setting xml tag is not valid."); } if (ct.XIsBlank()) { throw MException.MessageException("Setting xml tag had no value attribute."); } } Plaintext.Value = ct.XDecrypt(); } catch (Exception ex) { ex = AnalyzeException(ex); ex.XHandle("decrypting"); } finally { Impersonate(false); } }
private static Exception AnalyzeException(Exception ex) { if (ex.Message.StartsWith("Key not valid in specified state")) { ex = MException.MessageException(ex.Message + " - please verify that the username matches the user originally used to create this secure string."); } if (ex.Message.Contains("data is invalid")) { ex = MException.MessageException("The ciphertext data blob is invalid."); } return(ex); }