LacunaWebPKI: Certificate Operations
by Lacuna Software
HTML
<script src="https://rawgit.com/malsup/blockui/316f6e5d76a33266970778e80507149d9ef6a02d/jquery.blockUI.js"></script>
<script src="https://get.webpkiplugin.com/Scripts/LacunaWebPKI/lacuna-web-pki-2.9.0.js"></script>
<h2>Web PKI - RWE - Keyset not defined</h2>
<select id="certificateSelect"></select>
<button id="refreshButton" type="button">Refresh</button><br/><br/>
<button id="signHashButton" type="button">Sign Hash</button>
<div id="logPanel"></div>
<div id="blockPanel">
</div>
CSS
#blockPanel {
display: none;
padding: 0.5em;
}
JavaScript
// ------------------------------------------------------------------------------------------
// LacunaWebPKI: Certificate Operations
var pki = new LacunaWebPKI('ASYAanNmaWRkbGUubmV0LHdlYnBraS5sYWN1bmFzb2Z0d2FyZS5jb20AAAABClKvO1J22vAD+YmfANiKQLbcLE1lNraPKCel6tRM+ZxR+h6M/crtJYRRVGGz7hrdbM0Y0mfTu15RMYGqQMi1QNZS6GrT4vNzIayv552Fl0EFWQA7jWlctUwfYoHRHVEnCNx9YGXDiA9+yDoGlVwgTR7fjzNeS3Fen1MVIyKBF464gN0JvdiCRJMI47JGVDkPmKjcrYIvJs6y5Lg25RW4ZnBKVruS+HR2s3k8ZrV4y4RCQE4UYMKbukF9vsF+JqAEifRlPq2xLcrNdxBveVDSXS/LRHAcrZrMM+Iw4A79jl0ngWPcy+CwinAhT+3dxVo5ZWMRQFpmTkylEMDvTjV9wQ==');
function start() {
blockUI.start('Initializing component');
pki.init({
ready: onWebPkiReady,
defaultFail: function (ex) {
blockUI.stop();
log('Error: ' + ex.message + '(' + ex.code + ')');
}
});
}
function onWebPkiReady () {
refreshCertificates();
}
function refreshCertificates() {
blockUI.start('Listing certificates');
pki.listCertificates({
selectId: 'certificateSelect'
}).success(function (certs) {
blockUI.stop();
log(certs.length + ' certificates found.');
});
}
function signHash() {
var selectedCertThumb = $('#certificateSelect').val();
log('Signing hash with certificate: ' + selectedCertThumb);
pki.signHash({
thumbprint: selectedCertThumb,
hash: '3/1gIbsr1bCvZ2KQgJ7DpTGR3YHH9wpLKGiKNiGCmG8=', // Base64 encoding of the SHA-256 digest of the ASCII encoding of the string "Hello, World!"
digestAlgorithm: 'SHA-256'
}).success(function (signature) {
log('Result: ' + signature);
}).fail(function (ex) {
if (ex.code == pki.errorCodes.CSP_KEYSET_NOT_DEFINED) {
alert('Keyset not defined happened!');
// do something about it
}
alert('Message:\n' + ex.userMessage);
});
}
function log(message) {
$('#logPanel').append('<p>' + message + '</p>');
if (window.console) {
...