A newer version of this documentation is available.

View Latest

Design Advice

Scripting with the plugin object is usually very simple, below is some additional advice which may be helpful.

Reuse plugin object

Creating a plugin object will take some time when working with smart cards, so to enhance the user experience it is better to create a global plugin object and reuse the object.

This may also introduce some undesirable effects, since some properties are shared between operations. This is easily avoided using the ‘Reset’ operation before any other property is set for the new operation.

Example:
iid = document.getElementById(‘iid’);
if (iid != null) {
  iid.Invoke(‘Reset’);
  iid.SetProperty(‘<name>’, ‘<value>’);
  iid.SetProperty(‘<name>’, ‘<value>’);
  if (iid.Invoke(‘<name>’) == 0) {
  }
}

Complete operation to script function

There are no limitations. Create the object in one place among the HTML or script files, update somewhere else, and finally call some operation in a third location. However, this is not considered "good design" and will probably generate problems.

Instead create a script function which will cover the entire operation, for example (javascript):

function MySignOperation(data, cert) {
  var sign = "";
  var iid = null;
  iid = document.getElementById(‘iid’);
  if (iid != null) {
    iid.Invoke(‘Reset’);
    iid.SetProperty(‘Data’, data);
    iid.SetProperty(‘Certificate’, cert);
    iid.SetProperty(‘Base64’, ‘true’);
    iid.SetProperty(‘URLEncode’, ‘false’);
    if (iid.Invoke(‘Sign’) == 0) {
      sign = iid.GetProperty(‘Signature’);
    }
  }
  return sign;
}

There are several reasons for having the complete operation in a single function:

  • Easy to extract if support is needed, a single function to send to your support contact instead of a complete web site.

  • Easy to create load test when measuring performance.

  • Easy to support different PKI clients without updating the entire web site.