Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

Classic ASP Examples

Web API Categories

ASN.1
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
ECC
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
Geolocation
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text

HTTP
HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
NTLM
OAuth1
OAuth2
OneDrive
OpenSSL
Outlook
PEM
PFX/P12
POP3
PRNG
REST
REST Misc
RSA
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(Classic ASP) Create XAdES with ec:InclusiveNamespaces within the Transforms

Demonstrates how to generate XAdES that has a Reference that has Transforms that include an ec:InclusiveNamespaces.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
' This example requires the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.

' This is the XML we'll be signing:

' <soapenv:Envelope xmlns:obs="http://csioz.gov.pl/zsmopl/ws/obslugakomunikatow/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
' 	<soapenv:Header>
' 		<wsse:Security 
' 		    xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
' 		    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" soapenv:mustUnderstand="1">
' 			<wsse:BinarySecurityToken
' 				EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
' 				ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1"
' 				wsu:Id="X509-02BF0107214FC61449FD0013DF68F0359">MII...</wsse:BinarySecurityToken>
' 		</wsse:Security>
' 	</soapenv:Header>
' 	<soapenv:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" 
' 		wsu:Id="id-396BB6026342EB5C0E1EA73593B3CC098">
' 		<obs:zapiszKomunikatOS>
' 			<komunikatOS>
' 				<idPodmiotuRaportujacego>
' 					<idBiznesowy>000000011986</idBiznesowy>
' 					<rodzajPodmiotuRaportujacego>PA</rodzajPodmiotuRaportujacego>
' 				</idPodmiotuRaportujacego>
' 			</komunikatOS>
' 		</obs:zapiszKomunikatOS>
' 	</soapenv:Body>
' </soapenv:Envelope>
' 

' ----------------------------------------------------------------------
' IMPORTANT: This generated example requires Chilkat v9.5.0.77 or later.
' ----------------------------------------------------------------------
success = 1
' Create the above XML to be signed...
set xmlToSign = Server.CreateObject("Chilkat_9_5_0.Xml")
xmlToSign.Tag = "soapenv:Envelope"
success = xmlToSign.AddAttribute("xmlns:obs","http://csioz.gov.pl/zsmopl/ws/obslugakomunikatow/")
success = xmlToSign.AddAttribute("xmlns:soapenv","http://schemas.xmlsoap.org/soap/envelope/")
success = xmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security",1,"xmlns:wsse","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")
success = xmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security",1,"xmlns:wsu","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd")
success = xmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security",1,"soapenv:mustUnderstand","1")
success = xmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security|wsse:BinarySecurityToken",1,"EncodingType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary")
success = xmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security|wsse:BinarySecurityToken",1,"ValueType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1")
success = xmlToSign.UpdateAttrAt("soapenv:Header|wsse:Security|wsse:BinarySecurityToken",1,"wsu:Id","X509-02BF0107214FC61449FD0013DF68F0359")
' Note: The content of this XML node is a placeholder that will be updated below with the X509PKIPathv1 for the signing certificate.
xmlToSign.UpdateChildContent "soapenv:Header|wsse:Security|wsse:BinarySecurityToken","BinarySecurityToken_Base64Binary_Content"
success = xmlToSign.UpdateAttrAt("soapenv:Body",1,"xmlns:wsu","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd")
success = xmlToSign.UpdateAttrAt("soapenv:Body",1,"wsu:Id","id-396BB6026342EB5C0E1EA73593B3CC098")
xmlToSign.UpdateChildContent "soapenv:Body|obs:zapiszKomunikatOS|komunikatOS|idPodmiotuRaportujacego|idBiznesowy","000000011986"
xmlToSign.UpdateChildContent "soapenv:Body|obs:zapiszKomunikatOS|komunikatOS|idPodmiotuRaportujacego|rodzajPodmiotuRaportujacego","PA"

set gen = Server.CreateObject("Chilkat_9_5_0.XmlDSigGen")

gen.SigLocation = "soapenv:Envelope|soapenv:Header|wsse:Security"
gen.SigLocationMod = 0
gen.SigId = "SIG-BB965DFC3C8AAF87903C0ED898B8D2A8D"
gen.SigNamespacePrefix = "ds"
gen.SigNamespaceUri = "http://www.w3.org/2000/09/xmldsig#"
gen.SignedInfoCanonAlg = "EXCL_C14N"
gen.SignedInfoDigestMethod = "sha1"

' Set the KeyInfoId before adding references..
gen.KeyInfoId = "KI-9D95C38916099AD2EE87DDAC1A76E97E4"

' -------- Reference 1 --------
success = gen.AddSameDocRef("id-396BB6026342EB5C0E1EA73593B3CC098","sha1","EXCL_C14N","obs","")

' The reference to be produced in the Signature should look like this:

' <ds:Reference URI="#id-396BB6026342EB5C0E1EA73593B3CC098">
'     <ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#">
'         <ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="obs"></ec:InclusiveNamespaces>
'     </ds:Transform></ds:Transforms>
'     <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod>
'     <ds:DigestValue>2e9hZYj/CN2nPsgQqUraU43k3ds=</ds:DigestValue>
' </ds:Reference>
' 

' Provide a certificate + private key. (PFX password is test123)
set cert = Server.CreateObject("Chilkat_9_5_0.Cert")
success = cert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123")
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( cert.LastErrorText) & "</pre>"
    Response.End
End If

success = gen.SetX509Cert(cert,1)

gen.KeyInfoType = "Custom"

' Create the custom KeyInfo XML..
set xmlCustomKeyInfo = Server.CreateObject("Chilkat_9_5_0.Xml")
xmlCustomKeyInfo.Tag = "wsse:SecurityTokenReference"
success = xmlCustomKeyInfo.AddAttribute("wsse11:TokenType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1")
success = xmlCustomKeyInfo.AddAttribute("xmlns:wsse11","http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd")
success = xmlCustomKeyInfo.AddAttribute("wsu:Id","STR-FF238E7C061332C5B19752C2FBC8CDEF2")
success = xmlCustomKeyInfo.UpdateAttrAt("wsse:Reference",1,"URI","#X509-02BF0107214FC61449FD0013DF68F0359")
success = xmlCustomKeyInfo.UpdateAttrAt("wsse:Reference",1,"ValueType","http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509PKIPathv1")

xmlCustomKeyInfo.EmitXmlDecl = 0
gen.CustomKeyInfoXml = xmlCustomKeyInfo.GetXml()

' Load XML to be signed...
set sbXml = Server.CreateObject("Chilkat_9_5_0.StringBuilder")
success = xmlToSign.GetXmlSb(sbXml)

' Update BinarySecurityToken_Base64Binary_Content with the actual X509PKIPathv1 of the signing cert.
nReplaced = sbXml.Replace("BinarySecurityToken_Base64Binary_Content",cert.X509PKIPathv1())

gen.Behaviors = "IndentedSignature"

' Sign the XML...
success = gen.CreateXmlDSigSb(sbXml)
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( gen.LastErrorText) & "</pre>"
    Response.End
End If

' -----------------------------------------------

' Save the signed XML to a file.
success = sbXml.WriteFile("qa_output/signedXml.xml","utf-8",0)

Response.Write "<pre>" & Server.HTMLEncode( sbXml.GetAsString()) & "</pre>"

' ----------------------------------------
' Verify the signatures we just produced...
set verifier = Server.CreateObject("Chilkat_9_5_0.XmlDSig")
success = verifier.LoadSignatureSb(sbXml)
If (success <> 1) Then
    Response.Write "<pre>" & Server.HTMLEncode( verifier.LastErrorText) & "</pre>"
    Response.End
End If

numSigs = verifier.NumSignatures
verifyIdx = 0
Do While verifyIdx < numSigs
    verifier.Selector = verifyIdx
    verified = verifier.VerifySignature(1)
    If (verified <> 1) Then
        Response.Write "<pre>" & Server.HTMLEncode( verifier.LastErrorText) & "</pre>"
        Response.End
    End If

    verifyIdx = verifyIdx + 1
Loop
Response.Write "<pre>" & Server.HTMLEncode( "All signatures were successfully verified.") & "</pre>"

%>
</body>
</html>

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.