473,397 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

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 ShowCertificates()
{
string Info;
Store localMachineCertStore = new Store();

localMachineCertStore.Open(CAPICOM_STORE_LOCATION. CAPICOM_LOCAL_MACHINE_STORE,
"My", CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_READ_ON LY);

Certificates certificates =
(Certificates)localMachineCertStore.Certificates;

return certificates;
}

public void InstallCertificate(Certificate SelectedCert)
{
byte[] thumbprintByteArray = null;
string thumbprint = SelectedCert.Thumbprint;
MSAdminBaseClass adminBaseClass = new MSAdminBaseClass();
UtilitiesClass Utils = new UtilitiesClass();
string binaryThumbprint = Utils.HexToBinary(thumbprint);
thumbprintByteArray =
(byte[])Utils.BinaryStringToByteArray(binaryThumbprint);
adminBaseClass.SetMetabaseData(SslCertHashId, metaDataPath,
thumbprintByteArray);
adminBaseClass.SetMetabaseData(SslStoreNameId,
metaDataPath, "MY");
}

public void SetMetabaseData(uint metabaseDataId, string
metabaseDataPath, object data)
{
if(data == null)
throw new ArgumentNullException("data");

// Create METADATA_RECORD
METADATA_RECORD metaDataRecord = new METADATA_RECORD();
metaDataRecord.dwMDIdentifier = metabaseDataId;
metaDataRecord.dwMDAttributes =
(UInt32)METADATA_ATTRIBUTES.METADATA_INHERIT;
metaDataRecord.dwMDUserType =
(UInt32)METADATA_USER_TYPE.IIS_MD_UT_SERVER;

try
{
// Open MetaData Key
IntPtr metaDataKeyHandle = IntPtr.Zero;
try
{
IntPtr metaDataMasterRootHandle = new
IntPtr(METADATA_MASTER_ROOT_HANDLE);
adminBaseInterface.OpenKey(
metaDataMasterRootHandle,
"/LM",
(METADATA_PERMISSION_READ | METADATA_PERMISSION_WRITE),
20,
out metaDataKeyHandle);
if(metaDataKeyHandle == IntPtr.Zero)
throw new ExternalException("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)METADATA_TYPES.STRING_METADATA;
// Allocate String Data Memory (Add null terminated)
stringData += '\0';
metaDataRecord.dwMDDataLen =
(UInt32)Encoding.Unicode.GetByteCount(stringData);
metaDataRecord.pbMDData =
Marshal.StringToCoTaskMemUni(stringData);
if(metaDataRecord.pbMDData == IntPtr.Zero)
{
throw new Exception("Unable 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)METADATA_TYPES.BINARY_METADATA;
// Allocate Binary Data Memory
metaDataRecord.dwMDDataLen = (UInt32)binaryData.Length;
metaDataRecord.pbMDData =
Marshal.AllocCoTaskMem(binaryData.Length);
if(metaDataRecord.pbMDData == IntPtr.Zero)
{
throw new Exception("Unable to allocate binary data buffer for
Metabase entry.");
}
// Copy Binary Data to Unmanaged Memory
Marshal.Copy(binaryData, 0, metaDataRecord.pbMDData,
(int)metaDataRecord.dwMDDataLen);
}
string[] stringArrayData = data as String[];
if(stringArrayData != null)
{
// Set MetaData Record Type
metaDataRecord.dwMDDataType =
(UInt32)METADATA_TYPES.MULTISZ_METADATA;
ArrayList multiSzData = new ArrayList();
foreach(string stringData in stringArrayData)
{
// (Add null terminated)
multiSzData.AddRange(Encoding.Unicode.GetBytes(str ingData +
'\0'));
}
// (Add null terminated)
multiSzData.AddRange(new byte[2]{0x00,0x00});
binaryData =
(byte[])multiSzData.ToArray(Type.GetType("System.Byte"));
// Allocate Binary Data Memory
metaDataRecord.dwMDDataLen = (UInt32)binaryData.Length;
metaDataRecord.pbMDData =
Marshal.AllocCoTaskMem(binaryData.Length);
// Copy Binary Data to Unmanaged Memory
Marshal.Copy(binaryData, 0, metaDataRecord.pbMDData,
(int)metaDataRecord.dwMDDataLen);
}

}
else if(data is System.UInt32)
{
int uintData = (int)data;
// Set MetaData Record Type
metaDataRecord.dwMDDataType =
(UInt32)METADATA_TYPES.DWORD_METADATA;
// Allocate DWORD Data Memory
metaDataRecord.dwMDDataLen =
(uint)Marshal.SizeOf(typeof(UInt32));
metaDataRecord.pbMDData =
Marshal.AllocCoTaskMem((int)metaDataRecord.dwMDDat aType);
Marshal.WriteInt32(metaDataRecord.pbMDData, uintData);
if(metaDataRecord.pbMDData == IntPtr.Zero)
{
throw new Exception("Unable 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)METADATA_TYPES.DWORD_METADATA;
// Allocate DWORD Data Memory
metaDataRecord.dwMDDataLen =
(uint)Marshal.SizeOf(typeof(UInt32));
metaDataRecord.pbMDData =
Marshal.AllocCoTaskMem((int)metaDataRecord.dwMDDat aType);
Marshal.WriteInt32(metaDataRecord.pbMDData, intData);
if(metaDataRecord.pbMDData == IntPtr.Zero)
{
throw new Exception("Unable to allocate DWORD data buffer for
Metabase entry.");
}
}
#endregion Copy MetaData to Unmanaged Memory
// Set MetaData
adminBaseInterface.SetData(metaDataKeyHandle, metabaseDataPath,
ref metaDataRecord);
}
finally
{
// Close Key
adminBaseInterface.CloseKey(metaDataKeyHandle);
// Save Data
adminBaseInterface.SaveData();
}
}
finally
{
// Free Unmanaged Resources
if(metaDataRecord.pbMDData != IntPtr.Zero)
{
Marshal.FreeCoTaskMem(metaDataRecord.pbMDData);
}
}
}
}

Please help.

Varun

Sep 27 '06 #1
0 2340

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

Similar topics

0
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...
1
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....
1
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...
0
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...
0
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 :...
0
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...
1
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...
2
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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,...
0
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...

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.