WebConnect & PKCS11 add-on setup

Prerequisites

WebConnect must be installed. It is the basic framework which hosts the PKCS#11 add-on.

The web application must declare in its HTML code the following JavaScript libraries:

  • webconnect2_sc.js: The WebConnect library
  • webconnect2_sc_pkcs11.js: The SConnect PKCS11 wrapper, for compatibility with SConnect

Startup Flow

WebConnect is much simpler than SConnect. When setting up a connection between the browser and a card reader, the basic steps are:

  • Import the WebConnect library & SConnect PKCS11 wrapper
  • Initialize the PKCS11 library
  • Open a page session (web socket) to WebConnect
  • Initialize the card reader
  • WebConnect is now ready to send commands to your card reader

Shutdown Flow

The basic steps for stopping WebConnect are:

  • Close the page session (web socket connection)
  • Dispose of the PKCS11 object & resources

Here is an example of how to setup WebConnect with the SConnect wrapper:

                                
let SConnect; // This will hold the WebConnect instance
let theObjectPKCS11; // This will hold the PKCS11 instance

// Start the scenario, setup click listeners
$(document).ready(() => {
    $("#startTheScenario").click(() => {
        SConnect = WebConnect; // Imported from webconnect2_sc.js
        SConnect.PKCS11 = PKCS11; // Imported from webconnect2_sc_pkcs11.js
        SConnect.PKCS11.Create(createCallback); // Initializes the PKCS11 library, from the SConnect wrapper
    });
});

// In WebConnect (like in SConnect) callbacks usually run when the response arrives from the card reader
// createCallback runs when the WebConnect PKCS11 library has been initialized
const createCallback = {
    success: (p11) => {
        theObjectPKCS11 = p11;
        // Open a web socket connection to WebConnect
        theObjectPKCS11.webconnect.openPageSession(openPageSessionCallback, theObjectPKCS11.webconnect.pkcs7, onCloseListener);
    },
    error: (code) => {
        log(`ERROR: Failed to create PKCS11 instance (error code: ${code})`);
    }
};

// openPageSessionCallback runs once a page session has been started with the WebConnect backend
const openPageSessionCallback = {
    success: (status, data) => {
        console.log("Page session started");
        theObjectPKCS11.C_Initialize(initializeCallback);
    },
    error: () => {
        console.log("openPageSession failed, stopping execution...");
    }
}

// initializeCallback runs once the session with the card reader has been initialized
const initializeCallback = {
    success: (status, data) => {
        console.log("C_Initialize status: " + JSON.stringify(status));
        console.log("C_Initialize data: " + JSON.stringify(data));
    },
    error: (status) => {
        console.log("C_Initialize failed with status: " + JSON.stringify(status));
    }
};

// This listener will be called when the websocket closes, or times out
const onCloseListener = () => {
    window.alert("WebConnect has disconnected.");
}

// Releases all resources when the page is unloaded
window.onvisibilitychange = () => {
    if (document.visibilityState === "hidden") { theObjectPKCS11.dispose(); }
};
                                
                            

C_GetInfo

C_GetInfo returns general information about the PKCS11 in the form of a JSON object containing the CK_INFO properties.

                                
theObjectPKCS11.C_GetInfo(getInfoCallback);

const getInfoCallback = {
    success: (status, data) => {
        log("C_GetInfo succeeded!");
        log("C_GetInfo status: " + JSON.stringify(status));
        log("C_GetInfo data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_GetInfo failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

C_GetSlotList

C_GetSlotList is used to obtain a list of slots in the system.
The boolean parameter 'tokenPresent' indicates whether the list obtained includes only those slots with a token present (true), or all slots (false).

                                
// Get the list of slots with a token present
const tokenPresent = true;

// Invoke the function through the PKCS11 add-on instance
theObjectPKCS11.C_GetSlotList(tokenPresent, getSlotListCallback);

const getSlotListCallback = {
    success: (status, data) => {
        log("C_GetSlotList succeeded!");
        log("C_GetSlotList status: " + JSON.stringify(status));
        log("C_GetSlotList data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_GetSlotList failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

 

C_GetSlotInfo

C_GetSlotInfo obtains information about a particular slot in the system.
The number parameter 'slotID' is the ID of the slot.
The returned data is a JSON object containing the CK_SLOT_INFO properties.

                                
theObjectPKCS11.C_GetSlotInfo(slotId, getSlotInfoCallback);

const getSlotInfoCallback = {
    success: (status, data) => {
        log("C_GetSlotInfo succeeded!");
        log("C_GetSlotInfo status: " + JSON.stringify(status));
        log("C_GetSlotInfo data: " + JSON.stringify(data));
    },
    error: (status) => {
        console.log("FAIL C_GetSlotInfo");
        log("C_GetSlotInfo failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

C_GetTokenInfo

C_GetTokenInfo obtains information about a particular token in the system.
The number parameter 'slotID' is the ID of the slot.
The returned data is a JSON object containing the CK_TOKEN_INFO properties.

                                
theObjectPKCS11.C_GetTokenInfo(slotId, getTokenInfoCallback);

const getTokenInfoCallback = {
    success: (status, data) => {
        log("C_GetTokenInfo succeeded!");
        log("C_GetTokenInfo status: " + JSON.stringify(status));
        log("C_GetTokenInfo data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_GetTokenInfo failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Press this button to execute this sample code

Try it!

Click the button to invoke the function.

 

C_GetMechanismList

C_GetMechanismList is used to obtain a list of mechanism types supported by a token.
The number parameter 'slotID' is the ID of the slot.
The returned data is a [1..n] JSON array of number containing the supported CKM_xxx.

                                
theObjectPKCS11.C_GetMechanismList(slotId, getMechanismListCallback);

const getMechanismListCallback = {
    success: (status, data) => {
        log("C_GetMechanismList succeeded!");
        log("C_GetMechanismList status: " + JSON.stringify(status));
        log("C_GetMechanismList data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_GetMechanismList failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

C_GetMechanismInfo

C_GetMechanismInfo obtains information about a particular mechanism possibly supported by a token.
The number parameter 'slotID' is the ID of the slot.
The number parameter 'mechanismType' is the type of mechanism.
The returned data is a JSON object containing the CK_MECHANISM_INFO properties.

                                
const mechanismType = 1;
const slotId = 1;

theObjectPKCS11.C_GetMechanismInfo(slotId, mechanismType, getMechanismInfoCallback);

const getMechanismInfoCallback = {
    success: (status, data) => {
        log("C_GetMechanismInfo succeeded!");
        log("C_GetMechanismInfo status: " + JSON.stringify(status));
        log("C_GetMechanismInfo data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_GetMechanismInfo failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

C_InitToken

C_InitToken initializes a token.
The number parameter 'slotID' is the ID of the slot.
The string parameter 'pin' is the user’s PIN.
The string parameter 'label' is the token’s label.

                                
const slotId = 0;
const pin = "mySoPin";
const label = "MyLabel";

theObjectPKCS11.C_InitToken(slotId, pin, label, initTokenCallback);

const initTokenCallback = {
    success: (status) => {
        log("C_InitToken succeeded!");
        log("C_InitToken status: " + JSON.stringify(status));
        log("C_InitToken data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_InitToken failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

C_OpenSession

C_OpenSession opens a session between an application and a token in a particular slot.
The number parameter 'slotId' is the slot's ID.

                                
// Prepare to open a session on the slotId 1
const slotId = 0;

// Prepare the flags to open a RW session (CKF_SERIAL_SESSION | CKF_RW_SESSION = 6)
const flags = 6;

theObjectPKCS11.C_OpenSession(slotId, flags, openSessionCallback);

const openSessionCallback = {
    success: (status, data) => {
        log("C_OpenSession succeeded!");
        log("C_OpenSession status: " + JSON.stringify(status));
        log("C_OpenSession data: " + JSON.stringify(data));
    },
    error: (status) => {
        console.log(data);
        log("C_OpenSession failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

C_GetSessionInfo

C_GetSessionInfo obtains information about a session.
The number parameter 'sessionHandle' is the session’s handle.

                                
const sessionHandle = 2;
theObjectPKCS11.C_GetSessionInfo(sessionHandle, getSessionInfoCallback);

const getSessionInfoCallback = {
    success: (status, data) => {
        log("C_GetSessionInfo succeeded!");
        log("C_GetSessionInfo status: " + JSON.stringify(status));
        log("C_GetSessionInfo data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_GetSessionInfo failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

 

C_CloseSession

C_CloseSession closes a session between an application and a token.
The number parameter 'sessionHandle' is the session's handle.

                                
const sessionHandle = 2;
theObjectPKCS11.C_CloseSession(sessionHandle, closeSessionCallback);

const closeSessionCallback = {
    success: (status) => {
        log("C_CloseSession succeeded!");
        log("C_CloseSession status: " + JSON.stringify(status));
        log("C_CloseSession data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_CloseSession failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

C_CloseAllSessions

C_CloseAllSessions closes all sessions an application has with a token. When a session is closed, all session objects created by the session are destroyed automatically. After successful execution of this function, the login state of the token for the application returns to public sessions. Any new sessions to the token opened by the application will be either R/O Public or R/W Public sessions.
The number parameter 'slotId' is the slot’s ID.

                                
const slotId = 0;
theObjectPKCS11.C_CloseAllSessions(slotId, closeAllSessionsCallback);

const closeAllSessionsCallback = {
    success: (status) => {
        log("C_CloseAllSessions succeeded!");
        log("C_CloseAllSessions status: " + JSON.stringify(status));
        log("C_CloseAllSessions data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_CloseAllSessions failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

C_Login

C_Login logs a user into a token.
The number parameter 'sessionHandle' is the session's handle.
The number parameter 'userType' is the value of any CKU_xx.
The string parameter 'pin' is the user's PIN.

                                
const sessionHandle = 2;
const userType = 1;
const pin = "1234";
theObjectPKCS11.C_Login(sessionHandle, userType, pin, loginCallback);

const loginCallback = {
    success: (status) => {
        log("C_Login succeeded!");
        log("C_Login status: " + JSON.stringify(status));
        log("C_Login data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_Login failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

C_Logout

C_Logout logs a user out from a token.
The number parameter 'sessionHandle' is the session's handle.

                                
const sessionHandle = 2;
theObjectPKCS11.C_Logout(sessionHandle, logoutCallback);

const logoutCallback = {
    success: (status) => {
        log("C_Logout succeeded!");
        log("C_Logout status: " + JSON.stringify(status));
        log("C_Logout data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_Logout failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

C_InitPIN

C_InitPIN initializes the normal user's PIN.
The number parameter 'sessionHandle' is the session handle (see C_OpenSession to get one).
The plain text string parameter 'pin' is the user PIN.

                                
const sessionHandle = 1;
// The end-user PIN is a plain text string
const pin = "1234";
theObjectPKCS11.C_InitPIN(sessionHandle, pin, initPinCallback);

const initPinCallback = {
    success: (status) => {
        log("C_InitPIN succeeded!");
        log("C_InitPIN status: " + JSON.stringify(status));
        log("C_InitPIN data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_InitPIN failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

C_SetPIN

C_SetPIN modifies the PIN of the user that is currently logged in, or the user PIN if the session is not logged in.
The number parameter 'sessionHandle' is the session handle (see C_OpenSession to get one).
The string parameter 'oldPin' is the old PIN.
The string parameter 'newPin' is the new PIN.

                                
const sessionHandle = 1;
const oldPin = "1234";
const newPin = "5678";
theObjectPKCS11.C_SetPIN(sessionHandle, oldPin, newPin, closeAllSessionsCallback);

const closeAllSessionsCallback = {
    success: (status) => {
        log("C_CloseAllSessions succeeded!");
        log("C_CloseAllSessions status: " + JSON.stringify(status));
        log("C_CloseAllSessions data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_CloseAllSessions failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

C_CreateObject

C_CreateObject creates a new object.
The number parameter 'sessionHandle' is the session's handle.
The object parameter 'attributes' is the set of properties required to create the object. Each property name is the string of the CKA_xx attribute to set. Each property value is the value to set for the property.

                                
const sessionHandle = 2;
const attributes;

// The attribute name is any CKA_ characteristic as defined in the PKCS11 specification
// The attribute value can be a boolean, number, string or binary data expressed as unprefixed consecutive hexadecimal pairs ("010A" interpreted as [0x01, 0x0A]).
attributes.CKA_CLASS = 0;
attributes.CKA_TOKEN = true;
attributes.CKA_APPLICATION = [49, 50, 51, 52, 53, 54];
attributes.CKA_VALUE = [65, 66, 67, 68, 69, 70];

theObjectPKCS11.C_CreateObject(sessionHandle, attributes, createObjectCallback);

const createObjectCallback = {
    success: (status, data) => {
        log("C_CreateObject succeeded!");
        log("C_CreateObject status: " + JSON.stringify(status));
        log("C_CreateObject data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_CreateObject failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

C_DeleteObject

C_DestroyObject destroys an object.
The number parameter 'sessionHandle' is the session's handle.
The number parameter 'objectHandle' is the object's handle to delete.

                                
const sessionHandle = 2;
const objectHandle = 12;
theObjectPKCS11.C_DestroyObject(sessionHandle, objectHandle, destroyObjectCallback);

const destroyObjectCallback = {
    success: (status) => {
        log("C_DestroyObject succeeded!");
        log("C_DestroyObject status: " + JSON.stringify(status));
        log("C_DestroyObject data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_DestroyObject failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

C_GetAttributeValue

C_GetAttributeValue obtains the value of one or more attributes of an object.
The number parameter 'sessionHandle' is the session's handle.
The number parameter 'objectHandle' is the object's handle to get value from.
The array of number parameter 'attributes' is the set of CK_ATTRIBUTE_TYPE required to read. Each property name is the string of the CKA_xx attribute to get.

                                
const sessionHandle = 2;
const objectHandle = 12;
// Set a CK_ATTRIBUTE_TYPE array to get the CKA_CLASS (0x00000000), CKA_TOKEN (0x00000001) and CKA_VALUE (0x00000011) attribute of the object
const attributes = [0, 1, 11];
    
theObjectPKCS11.C_GetAttributeValue(sessionHandle, objectHandle, attributes, getAttributeValueCallback);

const getAttributeValueCallback = {
    success: (status, data) => {
        log("C_GetAttributeValue succeeded!");
        log("C_GetAttributeValue status: " + JSON.stringify(status));
        log("C_GetAttributeValue data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_GetAttributeValue failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

C_SetAttributeValue

C_SetAttributeValue modifies the value of one or more attributes of an object.
The number parameter 'sessionHandle' is the session’s handle.
The number parameter 'objectHandle' is the object's handle to set value.
The JSON object parameter 'attributes' is the set of properties to write. Each property name is the string of the CKA_xx attribute to set. Each property value is the value to set for the property.

                                
const sessionHandle = 2;
const objectHandle = 12;
const attributes;
    
// The attribute can be a boolean, number, string,
// or binary data (such as encrypted data) expressed as unprefixed consecutive hexadecimal pairs ("010A" interpreted as [0x01, 0x0A]).
attributes.CKA_CLASS = 0;
attributes.CKA_TOKEN = true;
attributes.CKA_LABEL = [116,101,115,116,48,49];

theObjectPKCS11.C_SetAttributeValue(sessionHandle, objectHandle, attributes, setAttributeValueCallback);

const setAttributeValueCallback = {
    success: (status) => {
        log("C_SetAttributeValue succeeded!");
        log("C_SetAttributeValue status: " + JSON.stringify(status));
        log("C_SetAttributeValue data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_SetAttributeValue failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

C_FindObjects

C_FindObjects initializes, continues and terminates a search for token and session objects that match a template

This function invokes internally the C_FindObjectsInit, C_FindObjects and C_FindObjectsFinal functions and sends back the result.

The number parameter 'sessionHandle' is the session’s handle.
The number parameter 'objectHandle' is the object's handle to set value.
The JSON object parameter 'attributes' is the set of properties to search for. Each property name is the string of the CKA_xx attribute to set. Each property value is the value to set for the property.

                                
const sessionHandle = 2;
const attributes;

// Search all the CKO_DATA available in the token
attributes.CKA_CLASS = 0;
    
theObjectPKCS11.C_FindObjects(sessionHandle, attributes, findObjectsCallback);

const findObjectsCallback = {
    success: (status, data) => {
        log("C_FindObjects succeeded!");
        log("C_FindObjects status: " + JSON.stringify(status));
        log("C_FindObjects data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_FindObjects failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

C_GenerateKeyPair

C_GenerateKeyPair generates a public/private key pair, creating new key objects.
The number parameter 'sessionHandle' is the session’s handle.
The number parameter 'mechanismType' is the mechanism type to generate with. The expected value is the value of a "CKM_xx" mechanism type.
The JSON object parameter 'attributesPublicKey' containing the attributes of the public key.
The JSON object parameter 'attributesPrivateKey' containing the attributes of the private key.
The 'success' callback returns the handles of thegenrated privtae and public keys.

                                
const sessionHandle = 2;
const mechanismType = 0; // value of CKM_RSA_PKCS_KEY_PAIR_GEN as defined into the PKCKS11 specification
const attributesKeyPublic = {};
const attributesKeyPrivate = {};
const signOnly = false;

// Add the attributes (see the PKCS11 specification for attributes list, type & usage)
attributesKeyPublic.CKA_MODULUS_BITS = 2048;
attributesKeyPublic.CKA_TOKEN = true;
attributesKeyPublic.CKA_CLASS = 2; // value of CKO_PUBLIC_KEY as defined into the PKCKS11 specification
attributesKeyPublic.CKA_KEY_TYPE = 0; // value of CKK_RSA as defined into the PKCKS11 specification
attributesKeyPublic.CKA_PRIVATE = false;
attributesKeyPublic.CKA_ENCRYPT = !signOnly;
attributesKeyPublic.CKA_WRAP = !signOnly;
attributesKeyPublic.CKA_VERIFY_RECOVER = true;
attributesKeyPublic.CKA_VERIFY = true;
attributesKeyPublic.CKA_ID = [116,101,115,116,48,49]; // Buffer containing the string "test01"
attributesKeyPublic.CKA_PUBLIC_EXPONENT = [1,0,1];
attributesKeyPrivate.CKA_TOKEN = true; 
attributesKeyPrivate.CKA_PRIVATE = true;
attributesKeyPrivate.CKA_EXTRACTABLE = false;
attributesKeyPrivate.CKA_SENSITIVE = true;
attributesKeyPrivate.CKA_DECRYPT = !signOnly;
attributesKeyPrivate.CKA_UNWRAP = !signOnly;
attributesKeyPrivate.CKA_SIGN_RECOVER = true;
attributesKeyPrivate.CKA_SIGN = true;
attributesKeyPrivate.CKA_ID = [116,101,115,116,48,49];

theObjectPKCS11.C_GenerateKeyPair(sessionHandle, mechanismType, attributesKeyPublic, attributesKeyPrivate, generateKeyPairCallback);

const generateKeyPairCallback = {
    success: (status, data) => {
        log("C_GenerateKeyPair succeeded!");
        log("C_GenerateKeyPair status: " + JSON.stringify(status));
        log("C_GenerateKeyPair data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_GenerateKeyPair failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

C_Encrypt

C_Encrypt initializes, continues and terminates an encryption operation.

This function invokes internally the C_EncryptInit, C_Encrypt and C_EncryptFinal functions and sends back the result.

The number parameter 'sessionHandle' is the session's handle.
The number parameter 'objectHandle' is the key object's handle to encrypt with.
The number parameter 'mechanismType' is the mechanism type to encrypt with. The expected value is the the value of a "CKM_xx" mechanism type.
The byte array object parameter 'data' is the data to encrypt (as [123, 124]).

                                
const sessionHandle = 2;
const keyObjectHandle = 12;
const mechanismType = 1; // Value of CKM_RSA_PKCS as described in the PKCS11 specification
const data = [12, 13, 14, 15, 16];
theObjectPKCS11.C_Encrypt(sessionHandle, keyObjectHandle, mechanismType, data, encryptCallback);

const encryptCallback = {
    success: (status, data) => {
        log("C_Encrypt succeeded!");
        log("C_Encrypt status: " + JSON.stringify(status));
        log("C_Encrypt data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_Encrypt failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

C_Decrypt

C_Decrypt initializes, continues and terminates a decryption operation.

This function invokes internally the C_DecryptInit, C_Decrypt and C_DecryptFinal functions and sends back the result.

The number parameter 'sessionHandle' is the session's handle.
The number parameter 'objectHandle' is the key object's handle to decrypt with.
The number parameter 'mechanismType' is the mechanism type to decrypt with. The expected value is the the value of a "CKM_xx" mechanism type.
The byte array object parameter 'data' is the data to decrypt (for example [123, 124]).

                                
const sessionHandle = 2;
const keyObjectHandle = 12;
const mechanismType = 1; // Value of CKM_RSA_PKCS as described in the PKCS11 specification
const data = [12, 13, 14, 15, 16];
theObjectPKCS11.C_Decrypt(sessionHandle, keyObjectHandle, mechanismType, data, decryptCallback);

const decryptCallback = {
    success: (status, data) => {
        log("C_Decrypt succeeded!");
        log("C_Decrypt status: " + JSON.stringify(status));
        log("C_Decrypt data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_Decrypt failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

C_Sign

C_Sign initializes, continues and terminates a signature operation.

This function invokes internally the C_SignInit, C_Sign and C_SignFinal functions and sends back the result.

The number parameter 'sessionHandle' is the session's handle.
The number parameter 'objectHandle' is the object's handle to sign with.
The number parameter 'mechanismType' is the mechanism type to sign with. The expected value is the the value of a "CKM_xx" mechanism type.
The byte array object parameter 'data' is the data to sign (as [123, 124]).

                                
const sessionHandle = 2;
const keyObjectHandle = 12;
const mechanismType = 1;
const data = [12,13,14,15,16];
theObjectPKCS11.C_Sign(sessionHandle, keyObjectHandle, mechanismType, data, signCallback);

const signCallback = {
    success: (status, data) => {
        log("C_Sign succeeded!");
        log("C_Sign status: " + JSON.stringify(status));
        log("C_Sign data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_Sign failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

C_Verify

C_Verify initializes, continues and terminates a signature verification.

This function invokes internally the C_VerifyInit, C_Verify and C_VerifyFinal functions and sends back the result.

The number parameter 'sessionHandle' is the session's handle.
The number parameter 'objectHandle' is the object's handle to verify with.
The number parameter 'mechanismType' is the mechanism type to verify with. The expected value is the the value of a "CKM_xx" mechanism type.
The byte array object parameter 'data' is the data to use for the verification (as [123, 124]).
The byte array object parameter 'signature' is the signature to verify (as [123, 124]).

                                
const sessionHandle = 2;
const keyObjectHandle = 12;
const mechanismType = 1;
const data = [12,13,14,15,16];
const signature = [123, 125, ...];
theObjectPKCS11.C_Verify(sessionHandle, keyObjectHandle, mechanismType, data, signature, verifyCallback);

const verifyCallback = {
    success: (status, data) => {
        log("C_Verify succeeded!");
        log("C_Verify status: " + JSON.stringify(status));
        log("C_Verify data: " + JSON.stringify(data));
    },
    error: (status) => {
        log("C_Verify failed with status: " + JSON.stringify(status));
    }
};
                                
                            

Try it!

Click the button to invoke the function.

 

Click here to try WebConnect!