![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(C#) S/MIME Decrypt, Verify Signatures, and Get AlgorithmsDemonstrates 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.
// 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-2025 Chilkat Software, Inc. All Rights Reserved.