Image:Encrypting documents in XPiNC

One of the nice things that sets XPiNC ( XPages in the Notes Client ) apart from XPages in the browser is the ability to encrypt documents using the native Notes encryption mechanisms.

I’ve just been working on a Proof of Concept for a proposal and had a few issues getting it to work so here are some notes :

> The encryption settings on the underlying form for the data source seem to have no impact at any time.

> You need to uses SSJS to programmatically set the encryption key for the document, the isEncrypted() property on the document and the isEncrypted() property on the field ( NotesItem ).

> When accessed via the browser the download control appears as empty

> When you access it via XPiNC without the certificate the download control appears empty

> There is some guidance from IBM at the links below but it is not great. Note that the method of setting the NotesItem.IsEncrypted property is setEncrypted(true) and not .IsEncrypted = true

NotesItem.IsEncrypted
NotesDocument.EncryptionKeys
NotesDocument.IsEncrypted
NotesDocument.encrypt

> You need to keep resetting the properties when you save the document otherwise it becomes un-encrypted.

> I added this code to my save button where the field test is used for attachments and the encryption certificate is called “commercial info”

<xp:button value=”this works” id=”button6″><xp:eventHandler event=”onclick” submit=”true” refreshMode=”complete”>
   <xp:this.action>

           <xp:actionGroup>
                   <xp:saveDocument var=”document1″></xp:saveDocument>

                   <xp:executeScript>
                           <xp:this.script><![CDATA[#{javascript:var doc:NotesDocument = currentDocument.getDocument();
var keys:java.util.Vector = doc.getEncryptionKeys();
keys.addElement(“commercial info”);
doc.setEncryptionKeys(keys);
doc.isEncrypted = true
var attachfield:NotesItem = doc.getFirstItem(“test”);
if (attachfield == null) {
print (“no item”)
} else {
attachfield.setEncrypted(true);
}

doc.encrypt();
doc.save()}]]></xp:this.script>
                   </xp:executeScript>
           </xp:actionGroup>
   </xp:this.action></xp:eventHandler></xp:button>