Javascript crypto.signText() Demo/Interop

Use the Redwax SignText web extension to allow signing of arbitrary text using a digital certificate.

Javascript crypto.signText()

The following example form shows how to trigger crypto.signText() to sign the given text.

Html Form

To request text be signed, submit the form below.

crypto.signText() returns a Promise which, when resolved, contains the signed text.

Detection

To detect presence of the API, call crypto.signText() without any parameters. If you receive a Promise in return, the new API is present..

Legacy Form

The original crypto.signText() as implemented by Netscape and then Firefox returned a string instead of a Promise. The following code shows the legacy behaviour, and should not be used in modern code.

Javascript

The javascript used to trigger the crypto.signText() functionality can be downloaded here, and is included for reference below.

function signRequest(form) {
  if (crypto.signText) {
    crypto.signText(form['tobesigned'].value).then(response => { form['signed'].value = response });
  }
  else {
    alert('An implementation of crypto.signText() is not installed in this browser.');
  }
}

function detectRequest(form) {
  if (crypto.signText) {
    crypto.signText().then(response => form['detected'].value = response.name + ' v' + response.version);
  }
  else {
    alert('An implementation of crypto.signText() is not installed in this browser.');
  }
}

function signLegacyRequest(form) {
  if (crypto.signText) {
    form['legacysigned'].value = crypto.signText(form['tobelegacysigned'].value, 'ask');
    return true;
  }
  else {
    alert('An implementation of crypto.signText() is not installed in this browser.');
  }
}