使用CAPICOM实现证书管理文档格式.docx

上传人:b****4 文档编号:6290106 上传时间:2023-05-06 格式:DOCX 页数:26 大小:26.95KB
下载 相关 举报
使用CAPICOM实现证书管理文档格式.docx_第1页
第1页 / 共26页
使用CAPICOM实现证书管理文档格式.docx_第2页
第2页 / 共26页
使用CAPICOM实现证书管理文档格式.docx_第3页
第3页 / 共26页
使用CAPICOM实现证书管理文档格式.docx_第4页
第4页 / 共26页
使用CAPICOM实现证书管理文档格式.docx_第5页
第5页 / 共26页
使用CAPICOM实现证书管理文档格式.docx_第6页
第6页 / 共26页
使用CAPICOM实现证书管理文档格式.docx_第7页
第7页 / 共26页
使用CAPICOM实现证书管理文档格式.docx_第8页
第8页 / 共26页
使用CAPICOM实现证书管理文档格式.docx_第9页
第9页 / 共26页
使用CAPICOM实现证书管理文档格式.docx_第10页
第10页 / 共26页
使用CAPICOM实现证书管理文档格式.docx_第11页
第11页 / 共26页
使用CAPICOM实现证书管理文档格式.docx_第12页
第12页 / 共26页
使用CAPICOM实现证书管理文档格式.docx_第13页
第13页 / 共26页
使用CAPICOM实现证书管理文档格式.docx_第14页
第14页 / 共26页
使用CAPICOM实现证书管理文档格式.docx_第15页
第15页 / 共26页
使用CAPICOM实现证书管理文档格式.docx_第16页
第16页 / 共26页
使用CAPICOM实现证书管理文档格式.docx_第17页
第17页 / 共26页
使用CAPICOM实现证书管理文档格式.docx_第18页
第18页 / 共26页
使用CAPICOM实现证书管理文档格式.docx_第19页
第19页 / 共26页
使用CAPICOM实现证书管理文档格式.docx_第20页
第20页 / 共26页
亲,该文档总共26页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

使用CAPICOM实现证书管理文档格式.docx

《使用CAPICOM实现证书管理文档格式.docx》由会员分享,可在线阅读,更多相关《使用CAPICOM实现证书管理文档格式.docx(26页珍藏版)》请在冰点文库上搜索。

使用CAPICOM实现证书管理文档格式.docx

capicom"

codeBase="

classid="

clsid:

A996E48C-D3DC-4244-89F7-AFA33EC60679"

VIEWASTEXT>

/OBJECT>

scriptlanguage="

javascript"

>

varCAPICOM_CURRENT_USER_STORE=2

varCAPICOM_MY_STORE="

My"

varCAPICOM_CERTIFICATE_FIND_SUBJECT_NAME=1

varCAPICOM_STORE_OPEN_READ_WRITE=1

varmyStore=newActiveXObject("

CAPICOM.Store"

);

myStore.Open(CAPICOM_CURRENT_USER_STORE,CAPICOM_MY_STORE,CAPICOM_STORE_OPEN_READ_WRITE);

varmyStoreCerts=myStore.Certificates;

varinfo="

"

;

for(i=1;

i<

=myStoreCerts.Count;

i++)

{info+="

SubjectName:

"

+myStoreCerts.Item(i).SubjectName+"

br/>

}

document.write(info);

/script>

.csharpcode,.csharpcodepre{font-size:

small;

color:

black;

font-family:

consolas,"

CourierNew"

courier,monospace;

background-color:

#ffffff;

/*white-space:

pre;

*/}.csharpcodepre{margin:

0em;

}.csharpcode.rem{color:

#008000;

}.csharpcode.kwrd{color:

#0000ff;

}.csharpcode.str{color:

#006080;

}.csharpcode.op{color:

#0000c0;

}.csharpcode.preproc{color:

#cc6633;

}.csharpcode.asp{background-color:

#ffff00;

}.csharpcode.html{color:

#800000;

}.csharpcode.attr{color:

#ff0000;

}.csharpcode.alt{background-color:

#f4f4f4;

width:

100%;

margin:

}.csharpcode.lnum{color:

#606060;

}

2、一个更复杂的例子:

2.1)、capicomtest.html

html>

head>

title>

CAPICOM使用DEMO<

/title>

metahttp-equiv="

no-cache"

/head>

bodyonLoad="

listCert()"

<

src="

capicom.js"

formname="

frmStore"

method="

post"

action="

1.读取用户证书

br>

证书类型:

selectid="

storeName"

size="

1"

name="

optionvalue="

my"

selected>

Personal<

/option>

root"

Root<

AddressBook"

AddressBook<

ca"

CA<

/select>

inputtype="

button"

value="

获取证书列表"

onclick="

/p>

p>

选择一个证书:

allCerts"

10"

>

inputid="

delcert"

type="

删除选定证书"

deleteCert()"

/>

verifydate"

验证选定证书有效期"

alert(verifyCertValidDate())"

/form>

/body>

/html>

2.2)、capicom.js

functiondeleteCert()

{

varmyStore=newActiveXObject("

try{

varstoreName=frmStore.storeName.options(frmStore.storeName.selectedIndex).value;

myStore.Open(CAPICOM_CURRENT_USER_STORE,storeName,CAPICOM_STORE_OPEN_READ_WRITE);

varindex=frmStore.allCerts.options.selectedIndex;

varcert=frmStore.allCerts.options[index].value;

subjectName=getCertCN(cert);

varmyStoreCerts=myStore.Certificates.Find(CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME,subjectName,true);

for(i=1;

{

if(myStoreCerts.Item(i).HasPrivateKey()){

//要删除用户证书,首先要删除私钥,才能够调用Certificates.Remove方法删除证书

myStoreCerts.Item(i).PrivateKey.Delete();

}

myStore.Remove(myStoreCerts.Item(i));

alert("

删除证书成功"

myStoreCerts=null;

myStore.Close();

myStore=null;

}catch(e){

删除证书失败,错误码为:

+e.number);

window.location.reload();

functionverifyCertValidDate(){

catch(e)

打开证书库失败"

return;

varresult="

varvalidToDate=newDate(myStoreCerts.Item(i).ValidToDate+"

varcurrentDate=newDate();

vardiff=(validToDate-currentDate)/(3600*24*1000);

if(diff>

31){

result="

证书"

+myStoreCerts.Item(i).subjectName+"

有效期为:

+formatDate(validToDate);

elseif(diff<

=31&

&

diff>

0){

+diff+"

后即将过期,请更新证书"

alert(result);

returnresult;

else{

已经过期,请更新证书"

if(result=="

return"

没有有效期"

functionlistCert()

try

myStore.Open(CAPICOM_CURRENT_USER_STORE,storeName,CAPICOM_STORE_OPEN_READ_WRITE);

returnfalse;

varcount=frmStore.allCerts.options.length;

for(i=1;

i<

=count;

frmStore.allCerts.options.remove(count-i);

while(frmStore.allCerts.options.length)frmStore.allCerts.options[0]=null;

//只列出DN中有的证书

varmyStoreCerts=myStore.Certificates.Find(CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME,"

true);

varcertInfo=newOption("

cert:

+myStoreCerts.Item(i).subjectName);

certInfo.value=myStoreCerts.Item(i).subjectName;

frmStore.allCerts.options.add(certInfo,i);

functiongetCertCN(dn){

//对于CAPICOM_CA_STORE、CAPICOM_OTHER_STORE、CAPICOM_ROOT_STORE不适用,需要调整

i=dn.indexOf('

CN='

if(i==-1){

没有CN"

}else{

cn=dn.substr(i+3);

returncn;

functionformatDate(inputDate){

if(null==inputDate){

//varyear=1900+date.getYear();

varyear=inputDate.getYear();

varmonth=inputDate.getMonth()+1;

if(month<

10)month="

0"

+month;

varday=inputDate.getDate();

if(day<

10)day="

+day;

varhour=inputDate.getHours();

if(hour<

10)hour="

+hour;

varminute=inputDate.getMinutes();

if(minute<

10)minute="

+minute;

varsecond=inputDate.getSeconds();

if(second<

10)second="

+second;

returnyear+"

-"

+month+"

测试代码打包下载

3、参考文档:

CAPICOMReference

HowtouseJavaproduceSignaturebyUSBKeyunderCryptoAPI/CSP

HowtocreateadigitalsigningsolutionwithonlyJavaScript

Howtoobtainsigner’sdetailsfromaJavaScriptsigneddata

AutomaticsignofatextinwithawebscriptusingCAPICOMwithanActiveX

数字证书在WEB应用中登录

IE中自动安装用户数字证书

Posted二月14,2010

Comments(3)

在基于ejbca搭建数字证书时候,需要实现用户自助申请数字证书(Certificatesigningrequest)并自动安装到IE浏览器中的功能(Certificateenrollment)。

相关的资料极其缺少,好在ejbca中有相关的例子可以参考,尽管不是很完整。

整理一下研究的大致成果。

1、基本思路:

1)、Certificatesigningrequest(CSR)

证书签发请求(CSR),也叫做证书请求,是从请求者浏览器发送到证书中心来申请一个数字身份证书的一条信息,在公共密钥基础架构系统中。

在创建一个CSR之前,这个请求者首先产生一个密钥对,为这个私有密钥保密。

CSR包括鉴别请求者一条的信息,和由这个请求者选择的公共密钥。

相应的私有密钥不包含在CSR中,但是被用于数位签名整个请求。

在XP、Windows2003的IE上,通过XEnroll.dll控件的createPKCS10方法来生成CSR(Certificatesigningrequest)。

在Vista,Windows2008,Windows7的IE上,需要使用CertEnroll.dll的X509Enrollment.CX509CertificateRequestPkcs10方法来生成CSR(Certificatesigningrequest)。

2)、用户数字证书的自动安装

要实现用户数字证书在IE浏览器中自动安装,首先要客户端浏览器提交CSR到证书中心服务器,证书中心服务器端根据CSR对用户私钥和公钥进行签名并将签名后的证书返回给客户端。

在XP、Windows2003的IE上,通过XEnroll.dll控件的acceptPKCS7方法实现证书自动安装到客户端浏览器,大致步骤如下:

objectid=”XEnroll”classid=”clsid:

127698e4-e730-4e5c-a2b1-21490a70c8a1″codebase=”xenroll.dll”>

/object>

XEnroll.acceptPKCS7

在Vista,Win

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2