views:

43

answers:

1

Is there any way to programmatically edit the purposes enabled for a give x.509 certificate?

This functionality is available via the certificates mmc snap-in (hyperlink below) but I need to perform the action through code. preferably C#.

modify the properties of a certificate

+1  A: 

The MMC can do whatever the Crypto API can do and there are a bunch of Certificate related functions like CertAddEnhancedKeyUsageIdentifier or CertSetCertificateContextProperty. There is a full blown example at Example C Program: Getting and Setting Certificate Properties, including a modification of the 'enhanced key usage' that specifies the uses for which a certificate is valid. For instance, to make a cert valid for SSL from the server side you'd have to add the EKU OID 1.3.6.1.5.5.7.3.1 (aka. 'Server Authentication'), see Configuring Certificate for Use by SSL.

The C# equivalent is the X509KeyUsageExtension class. See the link to the class spec for examples.

Remus Rusanu
Thank you. The C# x509keyusageextension would only modify the collection of certificates in memory, not the actual certificate store. Your links were very helpful. The Crypto API CertAddEnhancedKeyUsageIdentifier does modify the certificate in the store and only required a quick dllimport.
RSmith
Thanks for posting back the feedback. I wasn't aware of the differences between the real API and the managed one. I myself always used the Crypto API stuff directly.
Remus Rusanu