lotus-dominolotusscriptlotus

Encrypt Notes Database programmatically


I need to build a tool that can Encrypt databases on server.

So far I have found this info (but that's not enough).

  1. It's possible to check if database encrypted (works only locally) using NSFDbIsLocallyEncrypted.
  2. Make a replica W32_NSFDbCreateAndCopy and set Encryption while creating replica (that will be applied on replica).
  3. There is an undocumented Notes C API call that sets encryption flag for compact, but I could not make that work.

    STATUS far PASCAL NSFDbLocalSecInfoSet(DBHANDLE hDB, WORD Option, BYTE EncryptStrength, char far *Username);

  4. I have also read it is possible (for older ODS version) to change 'icon note' or to use DBINFO3 for newer ODS version (I could not make it work as well)

Does anybody know how to solve this task?

p.s. I have been told that HCL will come with proper solution in future (but not sure when).


Solution

  • Here is working code. I could not figure out, what to set as EncrytionStrength to remove local encryption using this code.

    %REM
    Agent encrypt
    Created Dec 22, 2019 by Ulrich Krause/singultus
    Description: Comments for Agent
    %END REM
    Option Public
    Option Declare
    
    Public Const W32_LIB = {nnotes.dll}
    Declare Function W32_NSFDbCompactExtended Lib W32_LIB Alias {NSFDbCompactExtended}  (ByVal Pathname As String, Options As Long, retStats As Long) As Integer
    Declare Function W32_NSFDbLocalSecInfoSet Lib W32_LIB Alias {NSFDbLocalSecInfoSet} (ByVal hDb As Long, ByVal wOptions As Integer, ByVal EncryptStrength As Integer, ByVal Username As String) As Integer
    Declare Function W32_NSFDbIsLocallyEncrypted Lib W32_LIB Alias {NSFDbIsLocallyEncrypted} ( ByVal hDB As Long, V As Integer) As Integer
    Declare Sub W32_OSLoadString Lib W32_LIB Alias {OSLoadString} (ByVal null1 As Long, ByVal sError As Integer, ByVal errstr As String, ByVal lenstr As Integer)
    Declare Function W32_NSFDbOpen Lib W32_LIB Alias {NSFDbOpen}(ByVal dbName As String, hDb As Long) As Integer
    Declare Function W32_NSFDbClose Lib W32_LIB Alias {NSFDbClose} (ByVal hDb As Long) As Integer
    Sub Initialize
    Dim hDb As Long
    Dim rc As Integer
    Dim sDb As String
    Dim retStats As Long
    
    sDb = "serv01/singultus!!crash.nsf"
    
    rc = W32_NSFDbOpen(sDb, hDb)
    
    If rc = 0 Then
        rc = W32_NSFDbLocalSecInfoSet(hDb, 0,1, "")
        msgbox GetError(rc)
    
        If rc = 0 Then
            rc = W32_NSFDbCompactExtended (sDb, 0, retStats)
        End if
        rc = W32_NSFDbClose(hDb)
    End If
    End Sub
    Function GetError (errnum As Integer) As String
    Dim s As String*256
    If IsDefined("WINDOWS") Then
        W32_OSLoadString 0, errnum And &h03FFFFFFF, s, 256
    Else
        'TUX_OSLoadString 0, errnum And &h03FFFFFFF, s, 256
    End If
    getError = StrLeft(s, Chr(0))
    End Function