Web申请个人证书代码


HTML的需要嵌入

IE微软的Object

<OBJECT
    	classid="clsid:127698e4-e730-4e5c-a2b1-21490a70c8a1"
    	CODEBASE="../xenroll.dll"
    	id=Enroll
    	>
</OBJECT>


CHROME

<KEYGEN TYPE="hidden" NAME="KeyAndChallenge" VALUE="">




Sub CertRequestSub
	
	Dim theForm
	Set theForm = document.forms(0)

	DN = ""
	
	'校验“国家”字段
	If theForm.Country.value <> Empty then
		If Len(theForm.Country.value) = 2 then
			DN = DN & "C=" & theForm.Country.value
		Else
			result = MsgBox("You must use the two character country code")
			Exit Sub
		End If
	Else
		result = MsgBox("You must supply a two character country code")
		Exit Sub
	End If

	'校验“省”字段
	If theForm.State.value <> Empty then
		If Len(theForm.State.Value) > 2 then
			DN = DN & ";S=" & theForm.State.value
		Else
			result = MsgBox("The State must be greater than 2 characters")
			Exit Sub
		End If
	Else
		result = MsgBox("You must supply a state name")
		Exit Sub 
	End if
	
	'校验“城市”字段
	If theForm.Locality.value <> Empty then
		DN = DN & ";L=" & theForm.Locality.value
	End If

	'校验“公司”字段
	If theForm.Org.value <> Empty then
		DN = DN & ";O=" & theForm.Org.value
	Else
		result = MsgBox("You must supply an Org name")
		Exit sub
	End If

	If theForm.OrgUnit.value <> Empty then
		DN = DN & ";OU=" & theForm.OrgUnit.value
	End If

	'校验“名字”字段
	If theForm.CommonName.value <> Empty then
		DN = DN & ";CN=" & theForm.CommonName.value
	Else
		result = MsgBox("You must supply a Common Name")
		Exit sub
	End If

	'校验“Email”字段
	If ((theForm.DNEMail.value <> Empty) AND (InStr(theForm.DNEMail.value, "@") <> 0)) then
		DN = DN & ";E=" & theForm.DNEMail.value
	Else
		result = MsgBox("You must supply an E-Mail address component")
		Exit Sub
	End If

	
	If theForm.KeyExportable.checked Then
		theForm.Enroll.GenKeyFlags = 1
	Else
		theForm.Enroll.GenKeyFlags = 0
	End If

	If theForm.IEKeyLength.value = "512" Then
		theForm.Enroll.GenKeyFlags = CLng(theForm.Enroll.GenKeyFlags) + CLng("33554432")
	ElseIf theForm.IEKeyLength.value = "1024" Then
		theForm.Enroll.GenKeyFlags = CLng(theForm.Enroll.GenKeyFlags) + CLng("67108864")
	ElseIf theForm.IEKeyLength.value = "2048" Then
		theForm.Enroll.GenKeyFlags = CLng(theForm.Enroll.GenKeyFlags) + CLng("134217728")
	Else
		result = MsgBox("Unexpected key-length: " & request.IEKeyLength.value)
		Exit Sub
	End If

	dim x
	for x = 0 to theForm.Elements.Length-1
		if theForm.Elements(x).Name = "HashType" then
			if theForm.Elements(x).Checked then
				value = theForm.Elements(x).Value
				Exit For
			End If
		End If
	Next
	
	theForm.Enroll.HashAlgorithm = value
	theForm.Enroll.KeySpec = 1
	theForm.Certificate.value = theForm.Enroll.CreatePKCS10(DN, "1.3.6.1.5.5.7.3.2")

	theError = Err.Number

	if (theForm.Certificate.value = Empty OR theError <> 0) Then
		
		sz = "The error '" & theError & "' occurred." & chr(13) & chr(10) & _
			"Your credentials could not be generated."
		result = MsgBox(sz, 0, "Credentials Enrollment")

		Exit Sub
	end if

	theForm.Submit

	Exit Sub

End Sub
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值