<%@ LANGUAGE=VBScript %>
<% Option Explicit %>
CAPICOM 2 SignedData Demo
<%
Dim iebrowser :iebrowser = True
iebrowser = InStr(1,Request.ServerVariables("HTTP_USER_AGENT"), "msie", 1)
If iebrowser then %>
<% End If %>
CAPICOM 2 SignedData Demo
M. Gallant 06/23/2002
<%
Dim Signer, Store, Certificates, Certificate
Dim fso, oContentFile
Dim SignedData, Message
Dim DataToSign : DataToSign = ""
Const MAX_DATA = 2700
Const CAPICOM_ENCODE_BASE64 = 0
Const CAPICOM_LOCAL_MACHINE_STORE = 1
Const CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME = 1
Const SubjectName = "Cert Name Substring"
Const FileToSign = "C:\Temp\contenttosign.txt"
If Request.TotalBytes > MAX_DATA Then
EndAsp("Too much data sent (" & Request.TotalBytes & " bytes). Limit is 2.7 kb")
End If
If Request.Form("datatosign") = "" Then
EndAsp("No data submitted.")
End If
DataToSign = Request.Form("datatosign")
Set fso = Server.CreateObject("Scripting.FileSystemObject")
' Write content to sign to archive file.
Set oContentFile = fso.OpenTextFile(FileToSign, 2, True)
oContentFile.write DataToSign
oContentFile.close
Set oContentFile = Nothing
Set Store = Server.CreateObject("CAPICOM.Store")
Set Store = Server.CreateObject("CAPICOM.Store")
Store.Open CAPICOM_LOCAL_MACHINE_STORE, "MY" ,0 'Open LocalMachine store for read
Set Certificates = Store.Certificates.Find(CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME, SubjectName)
'Response.Write(" Certificate found: " & Certificates.Count & Certificates(1).SubjectName)
Set Signer = Server.CreateObject("CAPICOM.Signer")
Signer.Certificate = Certificates(1)
Signer.Options = 0
Set Certificates = Nothing
Set Store = Nothing
Set SignedData = CreateObject("CAPICOM.SignedData")
SignedData.Content = DataToSign
On Error Resume Next
'Try to sign data-string with *attached* content and BASE64 endoced pkcs7
Message = SignedData.Sign(Signer, False, CAPICOM_ENCODE_BASE64)
If Err.Number <> 0 Then
Response.Write(" Sign Error: " & Err.Description & " " & Hex(Err.Number))
Else
If iebrowser Then
Response.Write(" ")
Response.Write(" ")
Response.Write(" ")
Else
Response.Write(vbCrLf & " Signed Data:")
End If
Response.Write(vbCrLf & "
" & Message & "
")
End If
Set SignedData = Nothing
Set Signer = Nothing
SUB EndAsp(message)
Response.Write(message)
Response.Write("")
Response.End
End Sub
%>