How to edit a password-protected PDF when you know the password
Make an authorized working copy with the known opening password, edit that copy, then apply the required protection to the finished document.
Use descriptive filenames for the temporary and final copies. After editing, verify the changed page, add password protection and test the final download in a fresh viewer. Follow your storage policy for the unencrypted working file.
Check signatures before editing a signed document. An authorized password allows access, but a change to the signed content can still affect signature validation.