This demonstrates possibilities on encrypting, signing, verifying message using the CAPICOM ActiveX and Javascript in a webbrowser. an ASP. NET developers can take note of this technique when you want to invoke to capicom dll to implement PKI infastructure using a browser. I know. net smartclient wowould have been another option where you can use. net Framework libraries to deal with x509certificates, but you might want to know this technique too:
Source blog: http://www.feed-squirrel.com/index.cfm? EVT = viewitem& id = 36269
- Use a memory store and in a Web page signs and verifies the sign
- Create an VB ActiveX with the following code and register it. Also, the CAPICOM dll must be registered. Both ActiveX cocould be downloaded from a web site)
- This code imports a PKCS #12 issued by a subordinader ca. If you want to get it contact me.
Function sign (text as string, p12path as string, p12password as string) as string
'This function imports a PKCS #12 container (private key and certificate to
'Memory store
Dim store as store
Dim signeddata as signeddata
Dim signer as signer
Set signer = new signer
Set signeddata = new signeddata
Set store = new store
Store. Open capicom_memory_store, "my", capicom_store_open_read_write
Store. Load p12path, p12password, capicom_key_storage_default
Signeddata. content = text
Signer. Certificate = store. Certificates. Item (1)
Szsigneddata = signeddata. Sign (signer, true, capicom_encode_base64)
Sign = szsigneddata
End Function
- Create a Web page with the following JavaScript Functions, invoking those from buttons
Function btnsigneddata_onclick ()
{
VaR signeddata = new activexobject ("automaticsign. asign ");
Try
{
Txtsigneddata. value = signeddata. Sign (txtplaintext. value, "C: \ c. p12", "1111 ");
}
Catch (E)
{
Alert ("an error occurred when attempting to sign the content );
Return false;
}
}
Function btnverifydata_onclick ()
{
VaR capicom_cert_info_subject_simple_name = 0;
VaR capicom_cert_info_issuer_simple_name = 1;
VaR capicom_verify_signature_only = 0;
// Instantiate the CAPICOM objects
VaR certificate = new activexobject ('capicom. certificate ');
VaR signeddata = new activexobject ('capicom. signeddata ');
Try
{
Signeddata. content = txtplaintext. value;
Signeddata. Verify (txtsigneddata. Value, true, capicom_verify_signature_only );
Certificate = signeddata. Certificates (2 );
Txtsignerdata. value = "Certificate:" + certificate. getinfo (capicom_cert_info_subject_simple_name) + "\ n ";
Txtsignerdata. Value + = "issuer:" + certificate. getinfo (capicom_cert_info_issuer_simple_name );
}
Catch (E)
{
Alert (E. Description );
Return false;
}
Alert ("signature verified ");
}