Decrypt my World

Cryptography, Security, Debugging and more!

Browse by Tags

Tagged Content List
  • Blog Post: 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...
  • Blog Post: 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;...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: 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...
  • Blog Post: 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;...
  • Blog Post: How to call CryptMsg API in streaming mode (C#)

    Hi all, The other day I posted an issue when signing large data with SignedCms in .NET (at least up to version 3.5 SP1): "ASN1 value too large" error when calling SignedCms.ComputeSignature . In that post, I mentioned the following to work around the issue: "we will have to p/invoke CryptMsg API and...
  • Blog Post: How to call InternetErrorDlg to deal with certificate issues on SSL connections (C#)

    Hi all, The following C# sample shows how to call WinInet APIs to make an SSL request and deal with possible certificate issues with InternetErrorDlg (which will show the same standard dialogs that Internet Explorer shows when something is wrong with server or client certs): using System; using System...
  • Blog Post: How to get information from a CRL (.NET)

    Hi all, The following C# sample uses CryptoAPI to read the info of a CRL ( Certificate Revocation List ) stored in a file: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using...
  • Blog Post: How to view a certificate programatically (C#)

    Hi all, The following C# sample shows a dialog to view a certificate and its properties . This is the same dialog that appears when we double-click on the cert file in Explorer. I'll use CryptUIDlgViewCertificate API and its CRYPTUI_VIEWCERTIFICATE_STRUCT structure to achieve this: ... using System...
  • Blog Post: How to sign EXE files with an Authenticode certificate (part 2)

    Hi all, welcome back, The other day a customer of mine was having an issue with SignTool.exe when signing an EXE file. The EXE file was getting corrupted /unusable after signing it. When troubleshooting this issue, I had the chance to play a bit more with SignTool and check what it does behind...
  • Blog Post: How to change Windows Theme programmatically in XP

    Hi all, You may know already that there is no i.e. COM object or .NET class we can use to change the Windows Theme programmatically on Windows XP . You may also know the following VBScript which can be used to do this change without user intervention: Set OSHApp = CreateObject(" Shell.Application...
  • Blog Post: How to sign a message and verify a message signature (C#)

    Hi all, welcome back, Today we'll do some more P/Invoke with CryptoAPI and C# . The following sample is a conversion to C# of the C++ sample in Example C Program: Signing a Message and Verifying a Message Signature : <SAMPLE file="Class1.cs"> using System; using System.Text; using System...
  • Blog Post: How to sign EXE files with an Authenticode certificate (VB.NET)

    Hi, welcome back, Sorry it took me so long to write a new post. I'm visiting my colleagues at Milano, and I'm horribly busy these days. For Windows platforms, below are the only supported methods we can use to digitally sign Authenticode executables: 1) We can use the old SignCode.exe tool ...
  • Blog Post: How to call CreateProcessWithLogonW & CreateProcessAsUser in .NET

    Hi, welcome back, Sometimes .NET 's System.Diagnostics.Process class and its Start method are not enough for our purposes and we need to call Win32 API directly from .NET ( P/Invoke mechanism) to be able to create a process the way we need. Here you have a sample you might find useful. It includes...
  • Blog Post: P/Invoking CryptoAPI in .NET (VB.NET version)

    Hi, welcome back, This is a continuation of my previous post, P/Invoking CryptoAPI in .NET (C# version) . Here you have the most common P/Invoke CryptoAPI declarations I've successfully used in the past, but this time for VB.NET ( Note: I've included a couple of auxiliary functions which may be...
  • Blog Post: P/Invoking CryptoAPI in .NET (C# version)

    Hi, welcome back, Sometimes we need to call CryptoAPI from .NET because classes in System.Security.Cryptography namespace have their limitations. For instance, we can't create a temporary key container with RSACryptoServiceProvider, but we can do it with CRYPT_VERIFYCONTEXT flag and CryptAcquireContext...
Page 1 of 1 (21 items)