capicom控件签名

var CAPICOM_CURRENT_USER_STORE = 2
var CAPICOM_MY_STORE = "My"
var CAPICOM_STORE_OPEN_READ_ONLY = 0
var CAPICOM_STORE_OPEN_EXISTING_ONLY = 128
var CAPICOM_CERTIFICATE_FIND_KEY_USAGE = 12
var CAPICOM_DIGITAL_SIGNATURE_KEY_USAGE = 128
var CAPICOM_CERT_INFO_SUBJECT_EMAIL_NAME = 2
var CAPICOM_HASH_ALGORITHM_SHA1 = 0 
var CAPICOM_VERIFY_SIGNATURE_AND_CERTIFICATE = 1
var CAPICOM_CERT_INFO_SUBJECT_SIMPLE_NAME = 0
var CAPICOM_CERT_INFO_ISSUER_SIMPLE_NAME = 1
var CAPICOM_CERT_INFO_SUBJECT_EMAIL_NAME = 2
var CAPICOM_CERT_INFO_ISSUER_EMAIL_NAME = 3
var CAPICOM_ENCODE_BASE64 = 0;
var CAPICOM_VERIFY_SIGNATURE_ONLY = 0;

function certLogin()
{
	var store = new ActiveXObject("CAPICOM.Store");
	var oSigner = new ActiveXObject("CAPICOM.Signer");
	var oSignedData = new ActiveXObject("CAPICOM.SignedData");

	store.Open(CAPICOM_CURRENT_USER_STORE, CAPICOM_MY_STORE, 
			CAPICOM_STORE_OPEN_READ_ONLY | CAPICOM_STORE_OPEN_EXISTING_ONLY);
	var certs = store.Certificates.Find(CAPICOM_CERTIFICATE_FIND_KEY_USAGE, 
			CAPICOM_DIGITAL_SIGNATURE_KEY_USAGE, true);
	certs = certs.Select();//弹出证书选择框
	var cert = certs (1);

	oSigner.Certificate = cert;
	oSignedData.Content = "123456";
	
	var signResult = oSignedData.Sign(oSigner, false, CAPICOM_ENCODE_BASE64);
	return signResult;
}


使用Capicom控件进行签名。

 

你可能感兴趣的:(PKI,Javascript)