Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Auto-Install PFX within Windows ServiceDemonstrates how to load a PFX from a Windows Service so that the private key is available for signing and decrypting. The certificate is loaded into the Local Machine Certificate Store once. After that, it should always be available.
bool bNeedPfxImport; bNeedPfxImport = true; Chilkat.Cert cert = new Chilkat.Cert(); bool hasPrivKey; // The LoadByCommonName method searches the registry-based // Windows Current User Certificate Store and Local Machine Certificate // Store for a certificate whose common name (CN) matches // the argument: bool success; success = cert.LoadByCommonName("Chilkat Software, Inc."); if (success == true) { hasPrivKey = cert.HasPrivateKey(); if (hasPrivKey == true) { // Certificate is available and has a private key that is accessible. bNeedPfxImport = false; } } // Do we need to load the PFX and import? if (bNeedPfxImport == true) { Chilkat.Pfx pfx = new Chilkat.Pfx(); bool bMachineKeyset; bMachineKeyset = true; bool bLocalMachineCertStore; bLocalMachineCertStore = true; bool bExportable; bExportable = true; bool bUseWarningDialog; bUseWarningDialog = false; success = pfx.ImportPfxFile("c:/pfxFiles/myPfx.pfx","myPassword",bMachineKeyset,bLocalMachineCertStore,bExportable,bUseWarningDialog); if (success == false) { // Failed to import the PFX. } else { // The certificate(s) within the PFX have been installed. // Now try loading again... success = cert.LoadByCommonName("Chilkat Software, Inc."); if (success == true) { hasPrivKey = cert.HasPrivateKey(); // We should have access to the private key now... } } } |
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.