Encrypt (NotesDocument - LotusScript®)

Encrypts a document in a database.

Defined in

NotesDocument

Syntax

Call notesDocument .Encrypt

Call notesDocument .Encrypt(userid)

Call notesDocument .Encrypt(idfile, password)

Parameter Description
userid NotesUserID (type). After setting the User id, documents in this database will be decrypted with encryption keys of this user id
idfile String. Provides the file path of id file. After setting it, all documents in this database will be decrypted with encryption keys of this id file.
password String. After setting the User id, documents in this database will be decrypted with encryption keys of this user id

Usage

General usage

The encrypted document is not written to disk until you call the Save method. Only the items for which the IsEncrypted property is True are encrypted. Items for which the IsEncrypted property is False remain visible to any user, even if the user does not have the proper encryption key.

If the EncryptionKeys property is set with one or more named keys, those keys are used to encrypt the document. Any user who has one of the encryption keys can decrypt the document. If there are no encryption keys specified, the document is encrypted with the user's public key, in which case only the user who encrypted the document can decrypt it.

If the script is running on a server, it must have permission to use Encrypt. If the script is part of a scheduled agent running in the background on a server, and the EncryptionKeys property is set with one or more named keys, the server's ID must contain those keys, not the signer of the agent. The agent must also have a runtime security level of at least "Allow restricted operations".

Since mail encryption works differently, don't use this method if you want to mail an encrypted document. Instead, set the EncryptOnSend property to True, and use the Send method.

You cannot use the encrypt method on a Document object returned by the DocumentContext property.

Usage with XPages

This method can also be used for encrypting XPages using the userid, idfile, and password parameters. To encrypt a document with a private key on web or server use the following general code steps:
'Fetch the IDVault object
Call Session.getIDVault

'Fetch a UserID object out of the IDVault for a particular user
Call notesIDVault.getUserIDFile(idFilePath, username, password, servername)

'Get a list of private key names that are available to use with the UserID
Call UserID.getEncryptionKeys()

'Use this method to specify which key to use to encrypt the doc
Call Document.setEncryptionKeys()

'Use this method to encrypt note with the specified encryption key set with setEncryptionKeys
Call Document.encrypt(UserID)      

Example

This code provides an example of how to use this method with the NotesIDVault:

Dim session As New NotesSession
	 
	Dim db As NotesDatabase
	Dim doc As NotesDocument

	Set db = session.getDatabase("TEST", "test1.nsf")
	Set doc = db.Createdocument()

	Dim item as New NotesItem(doc,"test","value")

	item.Isencrypted = true	
	Call doc.Save(True,False)

	Dim id As NotesIDVault
	Dim uid As UserID

	set id = session.getIDVault()
	Set uid = id.getUserID("test vault1", "12345", "TEST/IBM")
	
	Call doc.encrypt(uid)

Example