Domino Code Fragment

Code Name*
Agent for Encrypting Documents
Date*
04/28/2024
Source (or email address if you prefer)*
Rlatulippe@romac.com
IP address:.18.223.106.232
Description*
Agent for Encrypting Documents
Type*
LotusScript
Categories*
(Misc)
Implementation:
Required Client:
Server:
Limitations:
Comments:
Files/Graphics attachments (if applicable): Code:

%REM
----------------------------------------------------------------------------
FILE:    Agent for Encrypting Documents
UPDATED: April 1997
AUTHOR:  Eric Koeler
        mailto:ekoeler@panix.com
        http://www.panix.com/~ekoeler
NOTE:    Copyright (C) 1997 by Eric Koeler, this file is protected by the
        GNU General Public License
----------------------------------------------------------------------------
Let's say you've decided to implement encryption security in a Notes db
that already has quite a number of documents.  First, you generated a new
encryption key and distributed it to all of the users who will need access.
Next you added the encryption key name to the form's Properties (in the
"Default Encryption Keys" section).  For each of the fields you want to
encrypt, you set "Enable encryption for this field" in the Security Options
section of the Field Properties.

Now all new documents will encrypt the specified fields when they are
saved, but what about the documents already in the database?

 
You could go back and resave all of the documents, or you could run an
execute-once macro with the following formula:


      @Command([ToolsRefreshAllDocs]);

but these approaches could be incredibly slow if your form has alot of
input translation and validation formulas.  Below you'll find the code for
an agent that will encrypt and save all of the documents in the current
database in the back-end, which is super fast.  Just be sure to replace
the quoted strings with information specific to your situation.
----------------------------------------------------------------------------
%ENDREM


Sub Initialize

     On  Error Goto   ErrorHandler
    Dim sess  As New NotesSession
    Dim coll  As     NotesDocumentCollection
    Dim doc   As     NotesDocument
    Dim count As     Long
    Dim X     As     Long


     '----- Get all of the docs in the current database    
    Set coll = sess.CurrentDatabase.AllDocuments
    count = coll.Count
   
    For X = 1 To count
         Set doc = coll.GetNthDocument(X)


          '----- Set the name of the encryption key
         doc.EncryptionKeys = "Name of the Encryption Key"
         
         '----- Set the fields to be encrypted
         doc.GetFirstItem("FieldName1").IsEncrypted = True
         doc.GetFirstItem("FieldName2").IsEncrypted = True
         '...
         
         Call doc.Encrypt()
         Call doc.Save   (True, True)          
    Next X
    Exit Sub


ErrorHandler:
    Print Error$
    Resume Next


End Sub