Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicPythonRubySQL ServerSwiftTclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcel

C# Examples


ASN.1
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Bounced Email
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
ECC
Email Object
Encryption
FTP
Facebook
Firebase
GeoOp
Google APIs
Google Calendar
Google Cloud Storage
Google Drive
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
PayPal
Peoplevox
QuickBooks
REST
RSA Encryption
SCP
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
SharePoint
Shopify
Socket/SSL/TLS
Spider
Stream
Stripe
Tar Archive
Twitter
VoiceBase
Walmart
XML
XML Digital Signatures
XMP
Xero
Zip
curl
eBay

 

 

 

(C#) S/MIME Decrypt, Verify Signatures, and Get Algorithms

Demonstrates how to get the digest and encryption algorithms encountered when verifying signatures and decrypting S/MIME.

Note: This example requires Chilkat v9.5.0.69 or later.

Chilkat .NET Downloads

Chilkat .NET Assemblies

Chilkat for .NET Core

Chilkat for Mono

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

Chilkat.Mime mime = new Chilkat.Mime();

bool success = mime.LoadMimeFile("qa_data/smime/signed_and_encrypted_mime.txt");
if (success != true) {
    Debug.WriteLine(mime.LastErrorText);
    return;
}

success = mime.AddPfxSourceFile("qa_data/smime/secret.pfx","secret");
if (success != true) {
    Debug.WriteLine(mime.LastErrorText);
    return;
}

//  Call UnwrapSecurity to decrypt and verify signatures..
success = mime.UnwrapSecurity();
if (success != true) {
    Debug.WriteLine(mime.LastErrorText);
    return;
}

//  The information about what digest and encryption algorithms were encountered are
//  in the LastJsonData.  This is JSON that contains various pieces of information
//  depending on the method call.
Chilkat.JsonObject json = mime.LastJsonData();
json.EmitCompact = false;

Debug.WriteLine(json.Emit());

//  The JSON contains information such as the following:

//  	{
//  	  "pkcs7": {
//  	    "decrypt": [
//  	      {
//  	        "alg": {
//  	          "name": "aes",
//  	          "keySize": 128
//  	        }
//  	      }
//  	    ],
//  	    "verify": {
//  	      "digestAlgorithms": [
//  	        "sha256"
//  	      ]
//  	    }
//  	  }
//  	}

//  To iterate over digest and encryption algorithms:
int numEncAlgs = json.SizeOfArray("pkcs7.decrypt");
int i = 0;
while (i < numEncAlgs) {
    json.I = i;
    Debug.WriteLine("encAlg = " + json.StringOf("pkcs7.decrypt[i].alg.name"));
    Debug.WriteLine("keySize = " + Convert.ToString(json.IntOf("pkcs7.decrypt[i].alg.keySize")));
    i = i + 1;
}

int numDigestAlgs = json.SizeOfArray("pkcs7.verify.digestAlgorithms");
i = 0;
while (i < numDigestAlgs) {
    json.I = i;
    Debug.WriteLine("digest = " + json.StringOf("pkcs7.verify.digestAlgorithms[i]"));
    i = i + 1;
}


 

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