Encrypt field on document created by scheduled agent

I have a form with a text field for which encrypted is enabled. And the form specifies a default encryption key which i’ve created. I need to have a scheduled agent created documents using this form, and encrypt the specified field, using the specified secret encryption key. I have imported the specified secret encryption key into my user ID file, as well as the server’s ID file. If I run the agent using my ID, it works (creates the document and encrypts the field using the specified key). However, if I sign the agent with the server’s ID and then let it run on the schedule, no document is created and I see "Agent (‘agentName’ in ‘databaseName’) error message: Notes error: You don’t have any of the specified encryption keys.

The agent code is:

Sub Initialize

Dim session As New NotesSession

Dim db As NotesDatabase

Dim doc As NotesDocument

Set db = session.CurrentDatabase

Dim i As notesitem

Set doc = New notesdocument( db )

doc.form="testForm"

doc.processed="1"

doc.processedBy=Cstr(session.CommonUserName)

Set i = New NotesItem ( doc, "secret", "12345678" )

i.IsEncrypted = True

doc.EncryptionKeys = "customKey"

Call doc.Encrypt

Call doc.Save( False, False )

End Sub

As I mentioned, if I run the agent from the designer client using my ID file (which has the “customKey” in it), the document is created and the “secret” field is encrypted with the “customKey” key. However when the agent is signed by the server ID (which also has the “customKey” in it), it fails…

I’ve been searching the forum for a solution, but to no avail. Any help would be greatly appreciated. Thanks, Gigot

Subject: Encrypt field on document created by scheduled agent

Gigot,

The act of encrypting using a private encryption key is a UI event which is not supported in a scheduled agent.

my 2c,

raphael

Subject: Encrypt field on document created by scheduled agent

Gigot,

The act of encrypting using a private encryption key is a UI event which is not supported in a scheduled agent.

my 2c,

raphael

Subject: Encrypt field on document created by scheduled agent

The followings were what I did in sequence:(1) Create an encryption key named “topSecret” in the designer’s ID file

(2) Create a form named “keyMap”.

(3) Create a computed field named “SecretEncryptionKeys” with value “topSecret” (Designer 6.5.1 Help : To create a field that maintains a list of secret encryption keys) [Not sure if you have done this because you have not mentioned this]

(4) Click the Advanced tab. Select “Security options: Enable encryption for this field”

(5) create a field named “Secret” with option “Enable encryption for this field”

(6) set the form’s default encryption key to “topSecret”

(7) save and close the form

(8) export the encryption key from the designer’s ID file

(9) Backup the existing server id file. Import the encryption key to the server id file

(10)Sign the agent with the “designer’s” ID file [you signed the agent with server id]

Then the following scheduled agent works as expected (only those people who hold the encryption key

can see the value of field “Secret”):

Sub Initialize

Dim session As New NotesSession

Dim db As notesDatabase

Dim encryptDb As notesDatabase

Dim keyMapDoc As notesDocument

Dim secretItem As notesItem

Dim nowString As String



Print "Agent Start"

nowString = Format(Now, "yyyymmdd_hhnnss")

Set db = session.currentDatabase

Set encryptDb = session.GetDatabase( db.server, "EncryptDB" , False )

Set keyMapDoc = encryptDb.CreateDocument

keyMapDoc.form = "keyMap"

Set secretItem = New NotesItem( keyMapDoc, "Secret", "B1234" & nowString)

secretItem.IsEncrypted = True

keyMapDoc.mapKey = "1234" 

keyMapDoc.EncryptionKeys = "topSecret"

Call keyMapDoc.Encrypt

Call keyMapDoc.save(True, False)

Print "Agent End"

End Sub

Hope this help

Subject: RE: Encrypt field on document created by scheduled agent

Use this script to add the secret encryption key to the existing documents:

Sub Initialize

Dim Sess As New NotesSession

Dim doccoll As NotesDocumentCollection

Dim doc As notesdocument

Set doccoll = sess.CurrentDatabase.UnprocessedDocuments

Set doc = doccoll.GetFirstDocument

While Not doc Is Nothing

	Call doc.ReplaceItemValue("secretencryptionkeys","Test")

	Call doc.Encrypt

	Call doc.Save(True,False)

	Set doc = doccoll.getnextdocument(doc)

Wend

End Sub