Unable to export encrypted fields using agent

I have a database where I need to export the content of all fields on one document type, using a Lotusscript agent.

Two fields on the form are using field-level encryption. I have the key added to my ID file, but I cannot read the field values using the backend classes. The error is “Notes error: Access to data denied.”

If, using the same ID I use to execute the agent, I open the document in the Notes client, and save it, it works.

The export agent lives in a separate database, not in the database where the documents to export are located.

I tried to modify the agent to (using the backend classes) load the document, change the value of one field, and save it. This made no difference. It seems like the encrypted field is only decrypted/made available too the agent when I open and resave the document in the UI.
Ideas? Am I missing something?

Best to have such code in a button within the application.

Otherwise, check the permissions for the agent and ability of the current user to run unrestricted methods.
Also check who can execute unrestricted methods as per server security tab.

The agent in client would run on behalf of agent signer. So accessing your id file might be an issue.

Grant yourself all permissions in server document sign the agent your self. Allow agents to run unrestricted operations.
Now run the agent your self.
This may help you to debug the issue