/// <summary> /// Helper method for getting Zip password, and checking that it is valid /// </summary> protected DecryptResult GetZipPassword(IContentEncryptionUi ui) { string pwdDescription = string.Format(Resources.OpenPasswordRequired, DisplayShortName); string pwd = ShortTermPasswordCache.Instance.TryGetPassword(m_Attachment, "Zip"); if (pwd == null) { DecryptResult result = ui.GetPassword(Name, Resources.ZipPassword, pwdDescription, out pwd); if (result != DecryptResult.Ok) { return result; } if (string.IsNullOrEmpty(pwd)) { throw new UnauthorizedAccessException("Zip password required"); } } OpenPassword = pwd; ShortTermPasswordCache.Instance.AddPassword(m_Attachment, "Zip", pwd); return DecryptResult.Ok; }
/// <summary> /// Helper method for getting Document Protection password, and checking that it is valid /// </summary> protected DecryptResult GetDocumentProtectionPassword(IContentEncryptionUi ui) { if( RequiresDocumentProtectionPassword && string.IsNullOrEmpty(DocumentProtectionPassword) ) { // Check if there is an admin-defined default password string defaultDocumentPassword = string.Empty; if (this.AllowDefaultPassword) { defaultDocumentPassword = GetDefaultProtectionPassword(); } // If no password, then show the UI and allow the user to enter one. if( string.IsNullOrEmpty(defaultDocumentPassword) ) { string pwdDescription = string.Format(Resources.DocumentProtectionPasswordRequired, ShortName); string pwd = ShortTermPasswordCache.Instance.TryGetPassword(m_Attachment, "Protection"); if (pwd == null) { DecryptResult result = ui.GetPassword(Name, Resources.DocumentProtectionPassword, pwdDescription, out pwd); if (result != DecryptResult.Ok) { return result; } if (string.IsNullOrEmpty(pwd)) { throw new UnauthorizedAccessException("Document Protection password required"); } } DocumentProtectionPassword = pwd; ShortTermPasswordCache.Instance.AddPassword(m_Attachment, "Protection", pwd); } else { DocumentProtectionPassword = defaultDocumentPassword; } } return DecryptResult.Ok; }