How to use INTERNET_OPTION_SERVER_CERT_CHAIN_CONTEXT with InternetQueryOption in C#

Hi all, The other day I needed to use the certificate chain context (CERT_CHAIN_CONTEXT structure) returned by a call to InternetQueryOption, in C#. The call in C++ looks like this: PCCERT_CHAIN_CONTEXT CertCtx=NULL; … if (InternetQueryOption(hReq, INTERNET_OPTION_SERVER_CERT_CHAIN_CONTEXT, (LPVOID)&CertCtx, &cbCertSize)) { PCCERT_CHAIN_CONTEXT pChainContext=CertCtx; … } Some additional info about this call can be found here: Option Flags “INTERNET_OPTION_SERVER_CERT_CHAIN_CONTEXT…

0

How to create a memory mapped file with C# (Windows Vista / Windows 7)

Hi all,   The following C# sample shows how to create a memory mapped file and use private namespaces to allow access to specific groups of users:   FORM1.CS using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; using System.Security.Principal; using System.IO; namespace Alejacma { public…

0

How to verify signatures using a temporary keyset in .NET

Hi all, Some time ago a customer of mine had issues to verify signatures with RSACryptoServiceProvider when users had a mandatory and/or roaming profile, as he was getting the following exception: “System.Security.Cryptography.CryptographicException: Cryptographic Service Provider (CSP) for this implementation could not be acquired”. I already talked about this: RSACryptoServiceProvider fails when used with mandatory profiles….

0

More on .NET CMS classes and SHA-2 algorithms

Hi all,   We don’t officially support the .NET CMS classes with SHA-2 algorithms. This won’t work on Vista and later with third-party CSPs, for instance: “An internal error ocurred” when using SHA-2 algorithms with SignedCMS “Invalid provider type specified” when using CNG providers with .NET CMS classes   But it will work on Vista…

0

How to call CryptMsg API in streaming mode – LargeCMS full sample

Hi all Some time ago I posted a sample which shows how to sign large CMS data by calling CryptMsg API directly (How to call CryptMsg API in streaming mode (C#)) and that way overcome the current limitations of SignedCms in .NET (“ASN1 value too large” error when calling SignedCms.ComputeSignature). I continued working on the…

4

Big delay while calling EnvelopedCms constructor

Hi all,   You may experience a big delay when calling EnvelopedCms constructor in your .NET application if you have networking problems. For example, if DNS server is not available, a call to the constructor may take 30 to 90 seconds!!!   I could repro the issue by running the following code: DateTime before =…

2

How to enumerate all certificates on a smart card (PowerShell)

Hi all,   Some time ago I assisted my colleague Jeff Bowles with the development of a PowerShell script which enumerates all certificates on a smart card. Basically the replacement to CAPICOM.Store.Open CAPICOM_SMART_CARD_USER_STORE. He developed a sample that returns a System.Security.Cryptography.X509Certificates.X509Store object with the certificates in the card. The sample tries to emulate what logonUI.exe does during smart…

4

How to publish a printer in Active Directory (C#)

Hi all, We may publish a printer attached to our machine in Active Directory. To do that on Windows 7, for instance, we can go to “Devices and Printers” console, select “Printer Properties”, go to “Sharing” tab, and mark the “List in the directory” checkbox. That action will end up calling SetPrinter API to do…

0

P/Invoking CryptoAPI in .NET. Part 2 (C#)

Hi all, Some time ago I posted the following sample How to call CryptMsg API in streaming mode (C#).Well, I continued working on that CryptMsg sample, and I got many consts, structs and API declarations that may help you if you need to p/invoke CryptoAPI in C#. You may also want to check this other post…

2

How to call CryptEncodeObject in .NET (C#)

Hi all, The other day a colleague of mine was having some issues to call CryptEncodeObject from C#. In order to assist, I created this sample for him: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace WindowsFormsApplication1 { public partial class Form1 : Form {…

4