Reading encrypted fields with Lotusscript

Hello

I have a database with documents. On the documents are 2 fields which are encrypted with an key. I am using an user id with the encryption key included. I have tested this by opening a document. I can see the content of the encrypted fields.

But when I use the same id and access the same document with lotusscript I don´t see the encrypted fields. I cannot read the content of the fields using lotusscript.

Is there a way to read encryptd fields with lotusscript?

Regards

Subject: Reading encrypted fields with Lotusscript

You can use the C API call: NSFNoteDecrypt

Subject: RE: Reading encrypted fields with Lotusscript

Hi

Thank you for the info. I am not familiar with C API. Can I see an example somewhere on the internet?

Regards

Subject: RE: Reading encrypted fields with Lotusscript

I doubt that you will find a good sample on the Internet, but here is some code that you might want to use. It shows how you can open an database and open a document (= note) using its NoteID. I did not include the call to the function you want to use.

When you install the C API from Notes, you will also get a Help Database. Here you will find the details of all functions. The only drawback is, is that the help is based on the C interface. So when you call a function you will have to pay attention to the Lotusscript interface. Not all parametertypes can easily be converted from C to LS (especially the pointers). The following sample is only here to get you started.

Script Library: NoteHandling

[Declarations]

Private Const NOERROR = &H0000

Private Const UPDATE_FORCE = &H0001

Private Const OPEN_SHARE = &H0020

Private Const OPEN_EXPAND = &H0004

Declare Private Function NSFDbOpen Lib “nnotes.dll” (Byval dbname As Lmbcs String, dbH As Long) As Integer

Declare Private Function NSFDbClose Lib “nnotes.dll” (Byval hDb As Long) As Integer

Declare Private Function NSFNoteOpen Lib “nnotes.dll” (Byval hDB As Long, Byval NoteID As Long, Byval OpenFlags As Integer, rethNote As Long) As Integer

Declare Private Function NSFNoteClose Lib “nnotes.dll” (Byval hNT As Long) As Integer

Declare Private Function NSFNoteUpdate Lib “nnotes.dll” (Byval hNote As Long, Byval UpdateFlags As Integer ) As Integer

Declare Private Function OSPathNetConstruct Lib “nnotes.dll” (Byval portname As String, Byval servername As String, Byval filename As String, Byval pathname As String) As Integer

Declare Private Function OSLoadString Lib “nnotes.dll” (Byval hMod As Long, Byval strCode As Integer, Byval strBuf As String, Byval bufLen As Integer) As Integer

Private showError As Boolean

Sub Initialize

showError = False

End Sub

Function openDatabase(tserver As String, tdatabase As String) As Long

Dim dbp As String*256

Dim dbpath As String

Dim rc As Integer

Dim hDB As Long



rc = OSPathNetConstruct(Null, tserver, tdatabase, dbp)

dbpath = Trim$(dbp)

rc = NSFDbOpen(dbpath, hDB)

If rc <> NOERROR Then

	Call getError(rc, "NSFDbOpen")

	openDatabase = 0

Else

	openDatabase = hDB

End If

End Function

Sub closeDatabase(hDatabase As Long)

Dim rc As Integer



If hDatabase <> 0 Then

	rc = NSFDbClose(hDatabase)

	If rc <> NOERROR Then

		Call getError(rc, "NSFDbOpen")

	End If

End If

End Sub

Function openNoteByID(hDatabase As Long, noteID As String) As Long

Dim rc As Integer

Dim hNote As Long



rc = NSFNoteOpen(hDatabase, Hex2Long(noteID), OPEN_EXPAND, hNote)

If rc <> NOERROR Then

	Call getError(rc, "NSFNoteOpen")

	openNoteByID = 0

Else

	openNoteByID = hNote

End If

End Function

Function updateNote(hNote As Long) As Long

Dim rc As Integer



rc = NSFNoteUpdate(hNote, UPDATE_FORCE)

If rc <> NOERROR Then

	Call getError(rc, "NSFNoteUpdate")

End If

End Function

Function getError(rc As Integer, msg As String) As String

Dim errmsg As String*256

Dim emsg As String

Dim i As Integer



Call OSLoadString(0, rc, errmsg, 255)

i = Instr(errmsg, Chr$(0))

If i > 0 Then

	errmsg = Left$(errmsg, i - 1)

End If

getError = "Error: [" + Trim$(errmsg) + "]  executing: "  + msg

If showError Then

	Messagebox getError, 0, "Error"

End If

End Function

Sub setErrorType(show As Boolean)

showError = show

End Sub

Function closeNote(hNote As Long) As Long

Dim rc As Integer



If hNote <> 0 Then

	rc = NSFNoteClose(hNote)

	If rc <> NOERROR Then

		Call getError(rc, "NSFNoteClose")

	End If

End If

End Function

Function Hex2Long(ihex As String) As Long

’ Convert a hex string into a long

Dim arr As String

Dim i As Integer

Dim l As Long

Dim ilen As Integer

Dim c As Integer



arr = "0123456789ABCDEF"

l = 0

ilen = Len(ihex)

For i = 1 To ilen

	c = Instr(1, arr, Mid$(ihex, i, 1))

	If c > 0 Then

		c = c - 1

	End If

	l = l * 16 + c

Next

Hex2Long = l

End Function

==================

Here is some sample code to show how to use the functions:

[Options]

Use “NoteHandling”

[Initialize]

Dim hDB As Long

Dim hNote as Long

Dim tserver As String

Dim tdatabase as String

Dim noteID as String



hDB = openDatabase(tserver, tdatabase)

hNote = openNoteByID(hDB, noteID)

'...[do here what you have to do with the opened note]

Call updateNote(hNote)

Call closeNote(hNote)

Call closeDatabase(hDB)