Chilkat Examples

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

C# UWP/WinRT Examples

Web API Categories

ASN.1
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Azure Cloud Storage
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
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
MS Storage Providers
Microsoft Graph
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(C# UWP/WinRT) Create .p7s Compliant with ICP-Brazil Digital Signature Standard

Demonstrates how to create a .p7s signature that contains a data file, which in this case is a PDF. The .p7s will be compliant with the ICP-Brazil Digital Signature Standard.

Important: This example requires Chilkat v9.5.0.83 or later.

Chilkat Universal Windows Platform (UWP) / WinRT Downloads

Chilkat for the Universal Windows Platform (UWP)

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

Chilkat.Crypt2 crypt = new Chilkat.Crypt2();

// Any type of file can be signed.  It doesn't have to be a PDF.
string inFile = "qa_data/pdf/helloWorld.pdf";

Chilkat.BinData bd = new Chilkat.BinData();
bool success = bd.LoadFile(inFile);
if (success == false) {
    Debug.WriteLine("Failed to load " + inFile);
    return;
}

// Get the certificate we'll be using to sign.
Chilkat.Cert cert = new Chilkat.Cert();
success = cert.LoadPfxFile("qa_data/pfx/cert_test123.pfx","test123");
if (success == false) {
    Debug.WriteLine(cert.LastErrorText);
    return;
}

success = crypt.SetSigningCert(cert);
if (success == false) {
    Debug.WriteLine(crypt.LastErrorText);
    return;
}

// Set properties for signing...
crypt.HashAlgorithm = "sha256";

Chilkat.JsonObject jsonSigningAttrs = new Chilkat.JsonObject();
jsonSigningAttrs.UpdateInt("contentType",1);
jsonSigningAttrs.UpdateInt("signingTime",1);
jsonSigningAttrs.UpdateInt("messageDigest",1);
jsonSigningAttrs.UpdateInt("signingCertificateV2",1);

jsonSigningAttrs.UpdateString("policyId.id","2.16.76.1.7.1.1.2.3");
jsonSigningAttrs.UpdateString("policyId.hash","sW6Iu/dzIqZ5lbeQeHeO09DqfIhYe29tUYtxXo92o9U=");
jsonSigningAttrs.UpdateString("policyId.uri","http://politicas.icpbrasil.gov.br/PA_AD_RB_v2_3.der");
jsonSigningAttrs.UpdateString("policyId.hashAlg","SHA256");

// Don't forget to change "helloWorld.pdf" to the name of the file you desire. (it can be any type of file, it doesn't have to be a PDF)
jsonSigningAttrs.UpdateString("contentHint.text","Content-Type: application/octet-stream\r\nContent-Disposition: attachment;filename=\"helloWorld.pdf\"");
jsonSigningAttrs.UpdateString("contentHint.oid","1.2.840.113549.1.7.1");

crypt.SigningAttributes = jsonSigningAttrs.Emit();

// The Brazil government validator requires the ASN.1 data to be in "constructed octets" form..
crypt.UncommonOptions = "UseConstructedOctets,OmitAlgorithmIdNull";
crypt.IncludeCertChain = false;

// Sign. 
success = await crypt.OpaqueSignBdAsync(bd);
if (success == false) {
    Debug.WriteLine(crypt.LastErrorText);
    return;
}

// Save to a .p7s
success = bd.WriteFile("qa_output/helloWorld.pdf.p7s");

Debug.WriteLine("Success");

 

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