<< Click to Display Table of Contents >> Using the Authenticity Key |
If you have signed a DCD file with a key using dycodoc, the template file is signed at the same time at the moment you save the DCD document. You need to validate a signed template using the VPE API method LoadTemplateAuthKey(), otherwise you - nor anyone else - can load the signed template.
Example:
Run dycodoc, open sample2.dcd, and create a key by chosing from the menu "Tools | Keys" and pushing the button "Create" in the "Keys" dialog. Copy the parameters to the clipboard with
Ctrl-C and close the dialog.
Now assign the key as authentication key to sample2.dcd by chosing from the menu "File | Access Rights", activating the tab "Keys" in the "Access Rights for Document" dialog and pushing the upper "Assign" button (which is responsible for the authentication key). Close the dialog and save the document in order to assign the key to the template file, too.
Now enter the example source code below and replace the text "<your key goes here>" with the parameters you had copied into the clipboard (use Ctrl-V).
Sample Code for the VPE Control
Dim tpl as TVPETemplate
VPE.OpenDoc
On Error Goto ErrorHandler 'Enable error-handling routine
' example: VPE.LoadTemplateAuthKey("\dycodoc\samples\sample2.tpl", 1611942443, 198827155, -643266845, 273270745)
tpl = VPE.LoadTemplateAuthKey("\dycodoc\samples\sample2.tpl", <your key here>)
SetFields(tpl)
VPE.DumpTemplate(tpl)
VPE.Preview
Exit Sub 'Exit to avoid handler
ErrorHandler: 'Error-handling routine
Select Case Err.Number
case VPE_E_APIFAILED + vbOBJECTERROR 'Error caused by VPE API
If VPE.LastError = VERR_TPL_AUTHENTICATION Then
MsgBox("'sample2.dcd' has been modified.", "Error:", MB_OK);
ElseIf VPE.LastError = VERR_FILE_OPEN Then
MsgBox("'sample2.dcd' not found or no access rights.", "Error:", MB_OK); |
Else
MsgBox("'sample2.dcd' could not be read.", "Error:", MB_OK);
End If
Case Else
'Handle other situations here...
End Select
End Sub
Sample Code for the VPE DLL (C/C++)
VpeHandle hDoc = VpeOpenDoc(hWnd, "Sample", 0);
// example: VpeLoadTemplateAuthKey(hDoc, "\\dycodoc\\samples\\Sample2.tpl", 1611942443, 198827155, - 643266845, 273270745)
hTpl = VpeLoadTemplateAuthKey(hDoc, "\\dycodoc\\samples\\Sample2.tpl", <your key goes here>);
if (hTpl == NULL)
{
switch (VpeGetLastError(hDoc))
{
case VERR_TPL_AUTHENTICATION:
MessageBox(hWnd, "'sample2.dcd' has been modified.", "Error:", MB_OK);
break;
case VERR_FILE_OPEN:
MessageBox(hWnd, "'sample2.dcd' not found or no access rights.", "Error:", MB_OK);
break;
default:
MessageBox(hWnd, "'sample2.dcd' could not be read.", "Error:", MB_OK);
}
}
else
{
SetFields(hTpl);
VpeDumpTemplate(hDoc, hTpl);
VpePreviewDoc(hDoc, NULL, VPE_SHOW_NORMAL);
}
The above code validates the Authentication Key when loading the template. If the key is wrong an error message is displayed, otherwise the template is dumped into the VPE Document.