Solved

CAPICOM on 64 bit machine

Posted on 2011-03-08
11
2,312 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:Samooramad
11 Comments
 
LVL 13

Expert Comment

by:agarwalrahul
ID: 35070501
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35071562
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.

BuildPlatformTarget
0
 

Author Comment

by:Samooramad
ID: 35079181
you mean change it for the project which is referencing the CAPICOM dll right?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 

Author Comment

by:Samooramad
ID: 35079814
agarwalrahul,

I followed those steps and when registering the dll got this error ss
0
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 35080015
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".
0
 

Author Comment

by:Samooramad
ID: 35080389
still not working
0
 

Author Comment

by:Samooramad
ID: 35080407
what can i use instead of Capicom?
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 35082783
Here is what I found:

MSDN - Alternatives to Using CAPICOM
http://msdn.microsoft.com/en-us/library/cc778518%28v=vs.85%29.aspx
0
 

Accepted Solution

by:
Samooramad earned 0 total points
ID: 35085740
I tried a lot of stuff... finally found something I could use at (code is posted)

http://www.leandrodg.com.ar/blog/2010/03/encryption-and-decryption-with-x-509-certificates/

the only issue is when I run it, I get the outputed encrypted data with a few header lines before it. How do I get rid of that? any ideas?


Content-ID: {8463E39C-7BC6-4F0C-912F-27824D1D01E9}
Content-Description: body
Bcc:
MIME-Version: 1.0
Content-type: application/x-pkcs7-mime; smime-type=enveloped-data; name="smime.p7m"
Content-Transfer-Encoding: base64

MIIBtwYJKoZIhvcNAQcDoIIBqDCCAaQCAQAxgfIwge8CAQAwWDBSMQswCQYDVQQGEwJTQTENMAsG
A1UEChMEU0FNQTEbMBkGA1UECxMSU0FNQSBlVHJ1c3QgQ2VudGVyMRcwFQYDVQQDEw5TQU1BIFNo
YXJlZCBDQQICNgwwDQYJKoZIhvcNAQEBBQAEgYCD3qSwnhBeZK/xTNbHIDYKlOW3xhWJ3z106r1g
NPLNkHXoB5nPef+NqINZ56r/2CqxqQ3O30qL34WE7dikF7C6cVAdpVNTmghk/wkOy2olbge/hzfi
v+AXTVvI2k/Hd2TL3yvqzXn2kUs/cVEuJP+z4xFcvn8w2/TXAzDkHAtNDjCBqQYJKoZIhvcNAQcB
MBkGCCqGSIb3DQMCMA0CAToECJZmG/AMxJ5igIGAHZwD/mAQVXK199o5AS0Mx0/2gbIfvxDun6oT
mHul1j+4SkdmO4dd/32EwtoZb/vkkKtqQdsXKckdqKXqQsnzVs2LzJIKI+J6VCCmyBAaboyOPwls
J4TLAIycJVAlYaW4UGTcIIz9XjgK6BxSEZ4ad0iC52KSZgxLifuKidjXxqg=

0
 

Author Comment

by:Samooramad
ID: 35086133
figured it out

replaced this line:

string result = EnvelopEncryptedContent(encryptedContent);

with this line:

string result = encryptedContent;

Thanks all
0
 

Author Closing Comment

by:Samooramad
ID: 35126350
Thanks
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question