Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ Delphi FoxPro Java Perl Python Ruby SQL Server VBScript
|
Create / Verify Digital Signature This ASP script shows how to create and verify a digital signature using a certificate. <html>
<head>
<title>ASP Digital Signature Example</title>
</head>
<body>
<%
' Get an object to create a certificate store object
set ccs = Server.CreateObject("ChilkatCertificate.ChilkatCreateCS")
' Open the local machine certificate store.
set certStore = ccs.OpenLocalSystemStore()
' Find the certificate matching the email address "matt@chilkatsoft.com"
set cert = certStore.FindCertBySubjectE("matt@chilkatsoft.com")
' Create a Chilkat encryption instance to do the public-key encryption.
set crypt = Server.CreateObject("ChilkatCrypt2.ChilkatCrypt2")
' Use the digital certificate we obtained from the local machine store.
crypt.SetSigningCert cert
' Any value passed to UnlockComponent begins the 30-day trial.
unlocked = crypt.UnlockComponent("30-day trial")
stringToSign = "This is a test"
' Create a digital signature for the data.
' Return the signature as a hexidecimalized string.
crypt.EncodingMode = "hex"
signature = crypt.SignStringENC(stringToSign)
' Show the details of what happened during signing.
Response.write crypt.LastErrorHtml & "<br><br>"
' Show the signature
Response.write "Signature: " & signature & "<br><br>"
' Now check to see if the signature is valid.
' Use a different ChilkatCrypt2 object for demonstration purposes.
set crypt2 = Server.CreateObject("ChilkatCrypt2.ChilkatCrypt2")
crypt2.EncodingMode = "hex"
unaltered = crypt2.VerifyStringENC(stringToSign,signature)
if (unaltered = 1) then
Response.write "1) The message has not been altered<br><br>"
else
Response.write "1) The message has been altered!<br><br>"
end if
' Alter the message and check again.
alteredMessage = stringToSign & "."
unaltered = crypt2.VerifyStringENC(alteredMessage,signature)
if (unaltered = 1) then
Response.write "2) The message has not been altered<br><br>"
else
Response.write "2) The message has been altered!<br><br>"
end if
' Let's look at the cert that was used to sign...
set cert2 = crypt2.GetLastCert()
if not (cert2 is nothing) then
' Which cert was it?
Response.write "Certificate used: " & cert2.SubjectDN & "<br><br>"
' Has the certificate been revoked?
if cert2.Revoked then
Response.write "This certificate has been revoked!<br><br>"
end if
' Has the certificate expired?
if cert2.Expired then
Response.write "This certificate has expired!<br><br>"
end if
' Is the certificate signature valid?
if cert2.SignatureVerified = 0 then
Response.write "This certificate does not have a valid signature!<br><br>"
end if
' Does the certificate have a trusted root?
if cert2.TrustedRoot = 0 then
Response.write "This certificate does not have a trusted root!<br><br>"
end if
end if
%>
</body>
</html>
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.