How to check encryption key?

Hi All.

I have encrypted few fields in a form. I want to check whether the user has encrypted key or not? if he don’t have I want to popup a message like u dont have encrypt key…etc.

How to do in formula language in the click event (button)?

Subject: How to check encryption key?

First create a form “TestForm” enable it to have the encryted key.1)Add two fields :

a)User name

b)CanEncrypt

2)Create a view (EncryptKey) with one column with the field User Name (sorted), obviolusly seleting only the form “TestForm”

In the designer panel “Other”, “Database Resources”, “Database script”, “Postopen”

Enter the code

On Error Goto ErrorHandler 

Dim session As New NotesSession

Dim workspace As New NotesUIWorkspace

Dim db As NotesDatabase

Set db = session.CurrentDatabase



UserName=session.CommonUserName



Dim entry As NotesViewEntry

Dim vc As NotesViewEntryCollection



Set view = db.GetView("(EncryptKey)")

SearchKey = UserName

Set doc = view.GetDocumentByKey (SearchKey )

If doc Is Nothing Then

	Set doc  = New NotesDocument(db)

	doc.Form = "TestForm"

	doc.UserName = UserName

	doc.CanEncrypt = "Yes"

	

	Set item = doc.GetFirstItem("CanEncrypt")

	item.isEncrypted = True

	

	doc.EncryptionKeys = "Level3"

	Call doc.encrypt

	Call doc.Save(True, False)

Else

	Call doc.encrypt

	Call doc.Save(True, False)

End If

TheEnd:

Exit Sub

TheEnd2:

Call Source.Close

Exit Sub

ErrorHandler:

Dim cError As String

cError = Error$ 



pos = Instrbp(1, cError, "encryption keys")

If pos >1  Then

	Messagebox "Please contact the IT department to provide the Level3 key"

Else

	Messagebox cError

End If

Resume TheEnd2	

Good Luck !