日期:2014-05-17 浏览次数:20733 次
<%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <html> <head> <title>CAPICOM - SignedData Sample</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <script language="jscript"> var CAPICOM_CURRENT_USER_STORE = 2; var CAPICOM_STORE_OPEN_READ_ONLY = 0; var CAPICOM_ENCODE_BASE64 = 0; var CAPICOM_ENCODE_BINARY = 1; var CAPICOM_INFO_SUBJECT_SIMPLE_NAME = 0; var CAPICOM_INFO_ISSUER_SIMPLE_NAME = 1; var CAPICOM_INFO_SUBJECT_EMAIL_NAME = 2; var CAPICOM_INFO_ISSUER_EMAIL_NAME = 3; function SelectMySignCert() { //cert store var mystore = new ActiveXObject("CAPICOM.Store"); mystore.Open(CAPICOM_CURRENT_USER_STORE,"My",CAPICOM_STORE_OPEN_READ_ONLY); var certs= mystore.Certificates; //myca sign certs //var mycacerts= certs; var mycacerts= new ActiveXObject("CAPICOM.Certificates"); for(i=1;i<=certs.Count;i++) { //var issuer=certs.Item(i).IssuerName; //if(issuer.indexOf("CN=test")<0) // continue; //check key usage var ku=certs.Item(i).KeyUsage(); //if(!ku.IsDigitalSignatureEnabled) //not sign cert //continue; //add mycacerts.Add(certs.Item(i)); } if(mycacerts.Count==0) { if(window.confirm("没有找到MYCA签发的证书,\r\n请插入相应的Ekey再按确定")==true) return SelectMySignCert(); else return null; } //select cert //var certsel= mycacerts.Select("选择证书1","请选择证书1:",false); var certsel= mycacerts.Select(); if(certsel==null)return null; var cert= certsel.Item(1); // cert.Display(); return cert; } function SignText(strtext) { //select cert try{ var mysigncert= SelectMySignCert(); if(mysigncert==null)return null; //signed data var signer = new ActiveXObject("CAPICOM.Signer"); signer.Certificate = mysigncert; var signeddata = new ActiveXObject("CAPICOM.SignedData"); var utils = new ActiveXObject("CAPICOM.Utilities"); signeddata.Content = utils.BinaryStringToByteArray(str