473,789 Members | 2,781 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

capicom help

Hi all,

Iam trying to do some certificate management using CAPICOM
lib. Iam writing this website with a backend c#. All i want is know is
how to select the website on IIS to do certificate installation and
viewing. That is currently when i run my program from the ASP .NET dev
server it installs and views the certificates present in "Default Web
Site" of IIS Manager console. Lets say if i run a new website "xyz",
how can i do certificate management for that.

The is below.

public Certificates ShowCertificate s()
{
string Info;
Store localMachineCer tStore = new Store();

localMachineCer tStore.Open(CAP ICOM_STORE_LOCA TION.CAPICOM_LO CAL_MACHINE_STO RE,
"My", CAPICOM_STORE_O PEN_MODE.CAPICO M_STORE_OPEN_RE AD_ONLY);

Certificates certificates =
(Certificates)l ocalMachineCert Store.Certifica tes;

return certificates;
}

public void InstallCertific ate(Certificate SelectedCert)
{
byte[] thumbprintByteA rray = null;
string thumbprint = SelectedCert.Th umbprint;
MSAdminBaseClas s adminBaseClass = new MSAdminBaseClas s();
UtilitiesClass Utils = new UtilitiesClass( );
string binaryThumbprin t = Utils.HexToBina ry(thumbprint);
thumbprintByteA rray =
(byte[])Utils.BinarySt ringToByteArray (binaryThumbpri nt);
adminBaseClass. SetMetabaseData (SslCertHashId, metaDataPath,
thumbprintByteA rray);
adminBaseClass. SetMetabaseData (SslStoreNameId ,
metaDataPath, "MY");
}

public void SetMetabaseData (uint metabaseDataId, string
metabaseDataPat h, object data)
{
if(data == null)
throw new ArgumentNullExc eption("data");

// Create METADATA_RECORD
METADATA_RECORD metaDataRecord = new METADATA_RECORD ();
metaDataRecord. dwMDIdentifier = metabaseDataId;
metaDataRecord. dwMDAttributes =
(UInt32)METADAT A_ATTRIBUTES.ME TADATA_INHERIT;
metaDataRecord. dwMDUserType =
(UInt32)METADAT A_USER_TYPE.IIS _MD_UT_SERVER;

try
{
// Open MetaData Key
IntPtr metaDataKeyHand le = IntPtr.Zero;
try
{
IntPtr metaDataMasterR ootHandle = new
IntPtr(METADATA _MASTER_ROOT_HA NDLE);
adminBaseInterf ace.OpenKey(
metaDataMasterR ootHandle,
"/LM",
(METADATA_PERMI SSION_READ | METADATA_PERMIS SION_WRITE),
20,
out metaDataKeyHand le);
if(metaDataKeyH andle == IntPtr.Zero)
throw new ExternalExcepti on("Error occured opening IIS
Metabase!");

#region Copy MetaData to Unmanaged Memory

if(data is System.String)
{
string stringData = data as String;
// Set MetaData Record Type
metaDataRecord. dwMDDataType =
(UInt32)METADAT A_TYPES.STRING_ METADATA;
// Allocate String Data Memory (Add null terminated)
stringData += '\0';
metaDataRecord. dwMDDataLen =
(UInt32)Encodin g.Unicode.GetBy teCount(stringD ata);
metaDataRecord. pbMDData =
Marshal.StringT oCoTaskMemUni(s tringData);
if(metaDataReco rd.pbMDData == IntPtr.Zero)
{
throw new Exception("Unab le to allocate string data buffer for
Metabase entry.");
}
}
else if(data is System.Array)
{
byte[] binaryData = data as Byte[];
if(binaryData != null)
{
// Set MetaData Record Type
metaDataRecord. dwMDDataType =
(UInt32)METADAT A_TYPES.BINARY_ METADATA;
// Allocate Binary Data Memory
metaDataRecord. dwMDDataLen = (UInt32)binaryD ata.Length;
metaDataRecord. pbMDData =
Marshal.AllocCo TaskMem(binaryD ata.Length);
if(metaDataReco rd.pbMDData == IntPtr.Zero)
{
throw new Exception("Unab le to allocate binary data buffer for
Metabase entry.");
}
// Copy Binary Data to Unmanaged Memory
Marshal.Copy(bi naryData, 0, metaDataRecord. pbMDData,
(int)metaDataRe cord.dwMDDataLe n);
}
string[] stringArrayData = data as String[];
if(stringArrayD ata != null)
{
// Set MetaData Record Type
metaDataRecord. dwMDDataType =
(UInt32)METADAT A_TYPES.MULTISZ _METADATA;
ArrayList multiSzData = new ArrayList();
foreach(string stringData in stringArrayData )
{
// (Add null terminated)
multiSzData.Add Range(Encoding. Unicode.GetByte s(stringData +
'\0'));
}
// (Add null terminated)
multiSzData.Add Range(new byte[2]{0x00,0x00});
binaryData =
(byte[])multiSzData.To Array(Type.GetT ype("System.Byt e"));
// Allocate Binary Data Memory
metaDataRecord. dwMDDataLen = (UInt32)binaryD ata.Length;
metaDataRecord. pbMDData =
Marshal.AllocCo TaskMem(binaryD ata.Length);
// Copy Binary Data to Unmanaged Memory
Marshal.Copy(bi naryData, 0, metaDataRecord. pbMDData,
(int)metaDataRe cord.dwMDDataLe n);
}

}
else if(data is System.UInt32)
{
int uintData = (int)data;
// Set MetaData Record Type
metaDataRecord. dwMDDataType =
(UInt32)METADAT A_TYPES.DWORD_M ETADATA;
// Allocate DWORD Data Memory
metaDataRecord. dwMDDataLen =
(uint)Marshal.S izeOf(typeof(UI nt32));
metaDataRecord. pbMDData =
Marshal.AllocCo TaskMem((int)me taDataRecord.dw MDDataType);
Marshal.WriteIn t32(metaDataRec ord.pbMDData, uintData);
if(metaDataReco rd.pbMDData == IntPtr.Zero)
{
throw new Exception("Unab le to allocate DWORD data buffer for
Metabase entry.");
}
}
else if(data is System.Int32)
{
int intData = (int)data;
// Set MetaData Record Type
metaDataRecord. dwMDDataType =
(UInt32)METADAT A_TYPES.DWORD_M ETADATA;
// Allocate DWORD Data Memory
metaDataRecord. dwMDDataLen =
(uint)Marshal.S izeOf(typeof(UI nt32));
metaDataRecord. pbMDData =
Marshal.AllocCo TaskMem((int)me taDataRecord.dw MDDataType);
Marshal.WriteIn t32(metaDataRec ord.pbMDData, intData);
if(metaDataReco rd.pbMDData == IntPtr.Zero)
{
throw new Exception("Unab le to allocate DWORD data buffer for
Metabase entry.");
}
}
#endregion Copy MetaData to Unmanaged Memory
// Set MetaData
adminBaseInterf ace.SetData(met aDataKeyHandle, metabaseDataPat h,
ref metaDataRecord) ;
}
finally
{
// Close Key
adminBaseInterf ace.CloseKey(me taDataKeyHandle );
// Save Data
adminBaseInterf ace.SaveData();
}
}
finally
{
// Free Unmanaged Resources
if(metaDataReco rd.pbMDData != IntPtr.Zero)
{
Marshal.FreeCoT askMem(metaData Record.pbMDData );
}
}
}
}

Please help.

Varun

Sep 27 '06 #1
0 2368

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1807
by: Mario Rodriguez | last post by:
Hi, I'm using interop-Capicom in my C# application, but when I try to use the CAPICOM_SMART_CARD_USER_STORE flag the following exception raises: The system cannot find the file specified. at CAPICOM.StoreClass.Open(CAPICOM_STORE_LOCATION StoreLocation, String Store Name, CAPICOM_STORE_OPEN_MODE OpenMode) at sugef.sicveca.capaPresentacion.windows.FindCertnet.Main(String args) in d:\documents and settings\mrodriguez\my documents\visual...
1
2217
by: Neil S. | last post by:
I am writing an ISAPI filter which is using CAPICOM to encrypt and decrypt cookie information. I've found that the encryption string being returned by CAPICOM a has carriage control and line feed. (Hex 0d0a). My filter adds the header in the correct format, including the entire encrypted cookie value (set-cookie: mycookie=theEncryptedValue;path=/;). However, when the isapi filter finishes running, the browser only gets part of the...
1
1980
by: Mohit | last post by:
Hi Friends I did not know where to post this question, so am posting it on ASP.Net forum (so please excue me Has any one used CapiCom.DLL. I am having problems with it, and am wondering if it works with Windows 2003? So the question is, does CapiCom.DLL (Version 2.0.0.3) work with Windows 2003 I keep getting the following error messag "The recipient cannot be found in the EnvelopedData object." when i call the Decrypt method Please...
0
1156
by: Jonathan W. Zaleski | last post by:
I am trying to use the CAPICOM Package to Send Secure Emails, however, I am having a bit of trouble in getting it to work. I am able to get the proper certificate, and seemingly encode the 'EnvelopedData' correctly, but when attempting to open the sent message in Outlook I receive a: "Can't open this item. Your Digital ID name can not be found by the underlying security system." Error. I am unsure what this means exactly as it is not...
0
1462
by: Frederic ESNOUF \(MVP-ISA\) | last post by:
Hi, My question is about 3des, ... in fact the difference between 3DES with Capicom (VB) and VB.net With VB6/capicom, encrypting data is simple : message.Content = "This is my bank account : Azerty007" message.SetSecret "MyPassword' message.Algorithm.KeyLength = CAPICOM_ENCRYPTION_KEY_LENGTH_128_BITS message.Algorithm.Name = CAPICOM_ENCRYPTION_ALGORITHM_3DES
0
1162
by: John | last post by:
Hello, I am trying to create a dll that has a capicom reference in it. After I do the following: Dim message As New CAPICOM.EncryptedData I recompile my dll. I don't receive any errors or warnings at this point. Next, I take a generic application and import an inherited form from the dll and I get the error to check to see if the reference has already been added. I can leave the reference to capicom in the references section and...
1
1822
by: Fafnir | last post by:
Hi all. I'm gettings asn1 error in capicom during the signature verification. The problem is that i sign the document using russian cryptoprovider - CryptoPro and verification also uses this cryptoprovider. Signed files are passed via email(Microsoft Outlook). Some files(small) pass ok and some raise asn1 error. Does anybody know what i could do? I'm using WinXP, Visual Studio .net 2003, c# and Interop.Capicom. Thanks for help. Alex.
2
3858
by: stéphane bard | last post by:
Hi all, Has anyone ever used Python to work with Certificate Services in Windows? I'm trying to capicom dll with pywin32. I've found some reference about python and capicom in this mail archive http://mail.python.org/pipermail/python-win32/2006-March.txt but nothing really helpfull.
1
2573
by: CsharpDeveloper | last post by:
Hi, I have sucessfuly used the CAPICOM in .NET FrameWork, but when it comes to using in .NET Compact FrameWork it is giving me a COMException "Class not registered". I have created a Interop wrapper with .NET 2.0. I have used the following command to do it tlbImp "CAPICOM.dll" /namespace:CAPICOM /out:INTEROP.CAPICOM.dll The code snippet is as follows
0
9666
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9511
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10410
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10139
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9984
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9020
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7529
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6769
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
3701
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.