/// <summary> /// Helper method for getting Open and Modify passwords, and checking that they are valid /// </summary> protected DecryptResult GetAndCheckPasswords(IContentEncryptionUi ui) { if ((RequiresOpenPassword && string.IsNullOrEmpty(OpenPassword)) || (RequiresModifyPassword && String.IsNullOrEmpty(ModifyPassword))) { // Check if there are admin-defined default passwords string defaultOpenPassword = string.Empty; string defaultModifyPassword = string.Empty; if (this.AllowDefaultPassword) { defaultOpenPassword = GetDefaultOpenPassword(); defaultModifyPassword = GetDefaultModifyPassword(); } // If no passwords, then show the UI and allow the user to enter them. if (string.IsNullOrEmpty(defaultOpenPassword) && string.IsNullOrEmpty(defaultModifyPassword)) { string pwdOpen= ShortTermPasswordCache.Instance.TryGetPassword(m_Attachment, "Open"); string pwdModify = ShortTermPasswordCache.Instance.TryGetPassword(m_Attachment, "Modify"); string pwdDescription = string.Format(Resources.OpenPasswordRequired, DisplayShortName); if (pwdOpen == null && pwdModify == null) { DecryptResult result = ui.GetPasswords(Name, DisplayShortName, out pwdOpen, out pwdModify); if (result != DecryptResult.Ok) { return result; } if (string.IsNullOrEmpty(pwdOpen) && String.IsNullOrEmpty(pwdModify)) { throw new UnauthorizedAccessException("Password required"); } } OpenPassword = pwdOpen; ModifyPassword = pwdModify; ShortTermPasswordCache.Instance.AddPassword(m_Attachment, "Open", pwdOpen); ShortTermPasswordCache.Instance.AddPassword(m_Attachment, "Modify", pwdModify); } else { OpenPassword = defaultOpenPassword; ModifyPassword = defaultModifyPassword; } } return DecryptResult.Ok; }
private DecryptResult UnProtect(object doc, IContentEncryptionUi ui) { InitPasswordsList(doc); if (m_Passwords.Count > 0) return ui.GetPasswords(OriginalAttachment.Name, OriginalAttachment.Name, m_Passwords, OnPropertyChanged); return DecryptResult.Ok; }