The PKIFv2 C# Interface

The PKIF library includes a complete set of C# wrapper classes. The C# wrappers allow convenient access to the full power of PKIF through the .NET platform. These classes access PKIF using the Platform Invocation Services (PInvoke) interface. PInvoke is part of the ECMA/ISO C# specification.

Supported Platforms

The PKIF C# interface has been tested with Microsoft Visual Studio 2005 and the Microsoft .NET Framework version 2.0 running under Microsoft Windows XP Professional (32 bit edition). There are currently no known issues with the C# interface when operating in the above mentioned environment. The C# wrappers are implemented using the PInvoke interface. In theory, this should allow them to be easily ported to the Linux, Solaris, and Apple platforms using the Mono and DotGNU Portable.NET environments. However, these enviroments are currently unsupported and untested. Your mileage may vary.

Installation and Usage

The PKIF C# interface classes are included in the default PKIF installation. Under Microsoft Visual 2005, the C# wrappers can be used by adding "PKIF.Net.dll" as a project Reference.

There are several diffrences between the use of PKIFv2 when using C++ and C#.

Global PKIFv2 functions can be accessed using pkif_module.  For example to create a default mediator set the following code can be used:

IPKIFMediator m = pkif_module.MakeDefaultMediator();

To create a stand alone mediator or a colleague make_NewMediatorName functions.  After creating a mediator or a colleague in this manner it has to be freed using Examples section contains several examples of creationg a mediator/colleague collection.

Creating mediators and colleagues

Mediators and colleagues have to be greated and destroyed using special functions provided in pkif_module.

Creating new mediators

Creating new colleagues

Destroying mediators/colleagues

The following functions are used to destroy mediators and colleagues.

Accessing mediators, colleagues, and interfaces

PKIFv2 C# interface provides various functions to access mediators, colleagues, and interfaces.  These functions were added because C# does not support multiple inheritance so the only way to access mediator, colleagues and interfaces is through these functions. All the functions can be accessed through pkif_module.

Functions to retrieve build and validate interfaces from IPKIFMediator interface:

Functions to retrieve a mediator object from IPKIFMediator interface:

Functions to retrieve an IPKIFColleague interface object given a colleague class object:

Functions to obtain IPKIFMediator interface object given a mediator class object:

Extracting extensions and attributes from CMS objects

To extract extensions and attributes several functions can be found in pkif_module.

Functions to retrieve extensions from a x509 certificate object:

Functions to retrieve extensions from a CRL object:

Functions to retrieve extensions CRLEntry object:

Functions to retrieve unsigned attributes from SignerInfo object:

Functions to retrieve signed attributes from SignerInfo:

Functions that convert a specific attribute object into CPKIFAttributePtr:

Deleting crypto and hash context interfaces

IPKIFRawCryptContext, IPKIFHashContext, and IPKIFCryptContext objects must be freed  after use.  To free these object the following functios are used:
All these functions can be accessed through pkif_module.

API Documentation

The PKIF C# interface is implemented as a set of thin C# wrappers that access PKIF via PInvoke. With the exception of language specific types (numeric types, character types, etc), every effort has been made to maintain full API compatibility between the core PKIF library and the C# interface wrapper classes. As a result, the current PKIF documentation is applicable to the PKIF C# interface.

Notes on C# Types

Smart pointers used in C++ implementation of PKIFv2 are also found in C#.  They can be identified by Ptr suffix.

To create a smart pointer make_SmartPointerNamePtr() is used.  For example to create CPKIFCertificatePtr use the following code:

CPKIFCertificatePtr cert = pkif_module.make_CPKIFCertificatePtr();

All the make_ functions can be accessed through pkif_module.

Exception Handling

PKIF C# Examples

C# examples can be found here

Additional References