<!--
var SECUINTER_LOCAL_MACHINE_STORE = 0;
var SECUINTER_CURRENT_USER_STORE= 1;
var SECUINTER_MY_STORE = 0;
var SECUINTER_OTHER_STORE= 1;
var SECUINTER_CA_STORE= 2;
var SECUINTER_ROOT_STORE= 3;
var SECUINTER_SHA1_ALGORITHM= 1;
var SECUINTER_ALGORITHM_RC2=0;
var SECUINTER_ALGORITHM_DES = 6;


function IsSecuInterInstalled(oUtil)
{
	if(typeof(oUtil) == "object")
	{
		if( (oUtil.object != null) )
		{
			return true;
		}
	}

	return false;
}

/*选择证书,返回 X509Certificate
选择证书,本地计算机
storeType:SECUINTER_MY_STORE=0(个人);SECUINTER_OTHER_STORE:1(其他人)
isSignCert:true(sign cert);false(env cert)
*/
function getNetCACert(storeType,isSignCert)
{	
	var oUtil;
	var MyStore;
	try
	{
		oUtil = new ActiveXObject("SecuInter.Utilities");
		MyStore = new ActiveXObject("SecuInter.Store");
	}
	catch (e)
	{
		alert("安装不成功!");
		return null;
	}
	if(!IsSecuInterInstalled){
		alert("安装不成功!");
		return null;
        }

	try
	{
		MyStore.Open(SECUINTER_CURRENT_USER_STORE,storeType);
	}
	catch (e)
	{
		alert("打开证书库失败");
		return null;
	}
	var certs=MyStore.X509Certificates;
	MyStore.Close();
	MyStore = null;	
	
	var MyCerts = new ActiveXObject("SecuInter.X509Certificates");
	for(i=0;i<certs.Count;i++)
	{	
		issuer=certs.Item(i).Issuer;
		
	        if(issuer.indexOf("CN=NETCA")<0){
	        }
	        else{
	        	var iKeyUsage=certs.Item(i).KeyUsage;
	                if(iKeyUsage==-1){
	                	MyCerts.add(certs.Item(i));	
	                }
	                else{
		        				if(isSignCert==true){
		        						if(iKeyUsage%2==1&&iKeyUsage%4>=2){
		        								MyCerts.add(certs.Item(i));
		        						}
		                }
		                else{
		                	if(iKeyUsage%8>=4){
		                		MyCerts.add(certs.Item(i));	
		                	}
		                }
		              }
	        	}
	}

	if(MyCerts.Count>0){
	 return MyCerts.SelectCertificate();
	}
	window.status="";
	return null;

}

//取证书信息
function getCertInfo()
{	
	var cert=getX509Certificate(SECUINTER_MY_STORE,true);
	if(cert==null){
		return;
    	}
   	cert.Display();
   	alert("证书颁发者::"+cert.Issuer);
   	alert("证书序列号::"+cert.SerialNumber);
   	alert("证书主题::"+cert.Subject);
   	//alert("KeyUsage:   "+cert.KeyUsage);
   	alert("Subject的Email:   "+cert.GetInfo(2));
   	alert("Subject的名字:   "+cert.GetInfo(0));
   	alert("Subject的UPN:   "+cert.GetInfo(2));
}


var SECUINTER_CMS_ENCODE_BASE64=1;
//签名（签名内容）
function signNetCA(bContent,IsNotSource)//只显示NetCA证书
{	
	var oCert=getNetCACert(SECUINTER_MY_STORE,true);
	if(oCert==null){
		alert("未选择证书!");
		return null;
   	
   	}
   	var oSigner ;
   	var oSignedData ;
	try
	{
		oSigner = new ActiveXObject("SecuInter.Signer");
		oSignedData = new ActiveXObject("SecuInter.SignedData");
	}
	catch (e)
	{
		alert("安装不成功!");
		return null;
	}
   	
        oSigner.Certificate = oCert;
        oSigner.HashAlgorithm = SECUINTER_SHA1_ALGORITHM ;
        oSigner.UseSigningCertificateAttribute = false;
        oSigner.UseSigningTime = false;
        oSignedData.content = bContent;
        oSignedData.Detached = IsNotSource;
    
        var arrRT = oSignedData.sign(oSigner, SECUINTER_CMS_ENCODE_BASE64)
       
    	oSignedData = null;
    	oSigner = null;
        return arrRT;
}

//签名校验（签名原文，签名结果）
function verify(bContent,bSignData)
{	
   	var oSigner ;
   	var oSignedData ;
   	var oUtil;
	
	try
	{
		oSigner = new ActiveXObject("SecuInter.Signer");
		oSignedData = new ActiveXObject("SecuInter.SignedData");
		oUtil = new ActiveXObject("SecuInter.Utilities");
	}
	catch (e)
	{
		return -1;
	}
   	if( !oSignedData.verify(bSignData, 0) ){
   		return -2;
	}
	
   	if(oUtil.ByteArraytoString(bContent) != oUtil.ByteArraytoString(oSignedData.content))
   	{
   		 	return -3;
   	}
   	
	var iCertCount = oSignedData.Signers.Count;
	if(iCertCount = 1){
	    oSignedData.Signers.Item(0).Certificate.Display();
	}
	else{
	      for(var i = 0 ;i<iCertCount-1;i++){
	        oSignedData.Signers.Item(i).Certificate.Display();
	      }
        }
    	
    	oSignedData = null;
    	oSigner = null;
    	oUtil=null;
    	return 0;
}


//加密（加密内容，加密证书）
function env(bContent,oCert)
{	
	
   	var oEnv ;
	try
	{
		oEnv = new ActiveXObject("SecuInter.EnvelopedData");
	}
	catch (e)
	{
		alert("安装不成功!");
		return null;
	}
   	
        oEnv.Algorithm = SECUINTER_ALGORITHM_RC2;
        oEnv.Recipients.Add(oCert);
        oEnv.content = bContent ;
        var arrRT = oEnv.encrypt(SECUINTER_CMS_ENCODE_BASE64);
    	oEnv = null;
        return arrRT;
}

//解密（加密结果）
function dev(bEnvData)
{	
   	var oEnv ;
	try
	{
		oEnv = new ActiveXObject("SecuInter.EnvelopedData");
	}
	catch (e)
	{
		alert("安装不成功!");
		return null;
	}
   	oEnv.decrypt(bEnvData);
	var arrRt=oEnv.content;
   	
    	oEnv = null;
    	
    	return arrRt;
}

//-->