ASP. NET, JavaScript tips: encrypt/sign/verify signed message using CAPICOM ActiveX

Source: Internet
Author: User

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: 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 ");

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 ');
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 ");

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.