LacunaWebPKI.signData example
HTML
<script src="https://webpki.lacunasoftware.com/Scripts/LacunaWebPKI/lacuna-web-pki-1.3.3.js"></script>
<form>
<button id="startButton" type="button">Start</button>
<div id="signatureControlsPanel" style="display: block;">
<select id="certificateSelect"></select>
<button id="signButton" type="button">Sign Dummy Data</button>
</div>
</form>
<div id="logPanel"></div>
CSS
#signatureControlsPanel {
margin-top: 1em;
}
JavaScript
// ------------------------------------------------------------------------------------------
// LacunaWebPKI.signData example
function signDummyData() {
var selectedCertThumbprint = $('#certificateSelect').val();
if (selectedCertThumbprint == null || selectedCertThumbprint == '') {
alert('Select a certificate');
return;
}
var dataToSign = 'SGVsbG8sIFdvcmxkIQ=='; // ASCII encoding of the string "Hello, World!", encoded in Base64
log('Signing data ' + dataToSign + ' with certificate ' + selectedCertThumbprint + ' ...');
pki.signData({
thumbprint: selectedCertThumbprint,
data: dataToSign,
digestAlgorithm: 'SHA-256'
}).success(function (signature) {
log('Signature: ' + signature);
});
}
// ------------------------------------------------------------------------------------------
// The code from this point on is necessary for the example to run, but is not the focus of
// this specific example
var myLicense = {
"format": 1,
"allowedDomains": [
"jsfiddle.net",
"webpki.lacunasoftware.com"
],
"expiration": null,
"signature": "ClKvO1J22vAD+YmfANiKQLbcLE1lNraPKCel6tRM+ZxR+h6M/crtJYRRVGGz7hrdbM0Y0mfTu15RMYGqQMi1QNZS6GrT4vNzIayv552Fl0EFWQA7jWlctUwfYoHRHVEnCNx9YGXDiA9+yDoGlVwgTR7fjzNeS3Fen1MVIyKBF464gN0JvdiCRJMI47JGVDkPmKjcrYIvJs6y5Lg25RW4ZnBKVruS+HR2s3k8ZrV4y4RCQE4UYMKbukF9vsF+JqAEifRlPq2xLcrNdxBveVDSXS/LRHAcrZrMM+Iw4A79jl0ngWPcy+CwinAhT+3dxVo5ZWMRQFpmTkylEMDvTjV9wQ=="
};
var pki = new LacunaWebPKI({
license: myLicense,
defaultError: onWebPkiError
});
function onWebPkiError(message, error, origin) {
log('pki error from ' + origin + ': ' + message);
console.log(error);
}
function start() {
log('Checking component installation ...');
pki.checkInstalled({
installed: onWebPkiDetected,
notInstalled: function(status, message) {
log(message);
}
});
}
function onWebPkiDetected() {
log('Component...