Link to home
Start Free TrialLog in
Avatar of Samooramad
Samooramad

asked on

CAPICOM on 64 bit machine

Hi All,

I am using the capicom dll to sign some xml messages and send them using BizTalk. It was working fine on the test server, but on the production server which is 64 bit I get this error when CAPICOM dll is being called I get this error:

Retrieving the COM class factory for component with CLSID {94AFFFCC-6C05-4814-B123-A941105AA77F} failed due to the following error: 80040154.

so I did a little searching and apperently the capicom is not supported in 64 bit is the conclusion I have reached.

So my question is:
1- Is there anyway to make this work in 64 bit without needing to write some additional code?
2- If not, then how do I accomplish what is being done in the code below?
public string SignIt(string sClearText, bool bDetached)
        {
            EventLog.WriteEntry(
                    "SignatureMgr::SignIt",
                    WindowsIdentity.GetCurrent().Name,
                    EventLogEntryType.Information
                );

            SignedData signedData = new SignedDataClass();
            byte[] binArr = Encoding.UTF8.GetBytes(sClearText);
            Utilities utils = new CAPICOM.UtilitiesClass();
            signedData.set_Content(utils.ByteArrayToBinaryString(binArr));
            Store store = new Store();
                        store.Open(
                    CAPICOM_STORE_LOCATION.CAPICOM_LOCAL_MACHINE_STORE,
                    "MY",
                    CAPICOM_STORE_OPEN_MODE.CAPICOM_STORE_OPEN_READ_ONLY
                );

            Signer signer = new Signer();
                      string certSimpleName = null;
            foreach (object cert in store.Certificates)
            {
                certSimpleName =
                    ((Certificate)cert).GetInfo(CAPICOM_CERT_INFO_TYPE.CAPICOM_CERT_INFO_SUBJECT_SIMPLE_NAME).ToLower();
                System.Diagnostics.EventLog.WriteEntry(
                        "CSadadMessags::CMessageSigner",
                        certSimpleName + "=" + _certName,
                        System.Diagnostics.EventLogEntryType.Information
                    );

                             if (certSimpleName == _certName.ToLower())
                {
                    signer.Certificate = (Certificate)cert;
                    break;
                }
            }

            string signedText =
                signedData.Sign(
                    signer,
                    bDetached,
                    CAPICOM_ENCODING_TYPE.CAPICOM_ENCODE_BASE64
                );

                        return signedText;
        }

Open in new window

Avatar of Rahul Agarwal
Rahul Agarwal
Flag of India image

You could try to build your code to target x86 instead of x64 or Any CPU. This will force your application to run in 32-bit mode and possibly the CAPICOM dll will work.

User generated image
Avatar of Samooramad
Samooramad

ASKER

you mean change it for the project which is referencing the CAPICOM dll right?
agarwalrahul,

I followed those steps and when registering the dll got this error User generated image
Capicom isn't available in 64-bit. If you want to continue using capicom you have no choice but to force your project to 32-bit by setting it to x86.  Projects that reference other projects must match - i.e. a 64-bit project cannot reference a 32-bit project, so you will probably need to make sure all the projects in your solution are either "x86" or "AnyCPU".
still not working
what can i use instead of Capicom?
Here is what I found:

MSDN - Alternatives to Using CAPICOM
http://msdn.microsoft.com/en-us/library/cc778518%28v=vs.85%29.aspx
ASKER CERTIFIED SOLUTION
Avatar of Samooramad
Samooramad

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
figured it out

replaced this line:

string result = EnvelopEncryptedContent(encryptedContent);

with this line:

string result = encryptedContent;

Thanks all
Thanks