Wrap a 32-bit dll for a 64-bit operating system to work with regsvr32.exe

We are currently migrating our websites from Windows 2003 (32-bit) to Windows 2008 (64-bit) and are experiencing a problem.

One of our sites uses the HSBC CPI payment gateway, which requires the registration of a DLL (regsvr32.exe), this DLL is then used inside the classic asp website. The problem is that the DLL is a 32-bit DLL and therefore will not register in the Windows 2008 operating system.

Is there a way to wrap this 32-bit dll in a C # .net project so that its methods are open and can be registered with the OS?

Any help would be greatly appreciated.

+7
c # asp-classic
source share
3 answers

You can register the DLL with regsvr32.exe from the folder C: \ Windows \ SysWOW64.

However, since you cannot mix 64/32-bit code, you need to create a C # service running in x86 (see project properties, target platform), which you can then use from your x64-based web application via WCF.

A simpler option is to request HSBC for the x64 dll.

+5
source share

If you want to register a 32-bit COM-dll created using VC ++ or Visual Basic 6.0, you need to follow these steps without making any changes to the code. It also does not require compilation, and you also do not need to run IIS in WOW mode. I ran into this problem a few years ago and I solved this problem and it works great for me.

Scenario:

Let me assume that you have a third-party 32-bit COM library provided by the provider. The DLL works fine on a 32-bit operating system, and as soon as you go into the x64 environment, it doesn't work, although you tried to register it through regsv32.

Also let me assume that the DLL name is "ASXUpload.DLL". I will use this name in the solution that I provide below.

Decision

Please follow these steps:

  • First of all, if you have already registered the DLL in the x64 Operating System, unregister the DLL. To do this, simply enter the following at the command line "regsvr32 / u": "regsvr32 / u C: \ MyDLL \ ASXUpload.DLL". If you have not already registered the DLL from x64, you do not need to run this step.

  • Also, make sure that you do not save your DLL inside the Windows folder, which is usually C: \ Windows. In this example, I saved the DLL in the following folder C: \ MyDLL.

  • Now we need to add COM + components using Microsoft component services. To start Component Services, go to Control Panel / Administrative Tools / Component Services. After the internal service of the component is deployed to Computers, then My computer, and then COM + Applications. Then right-click COM + Applications and choose New → Application.

  • In the "Welcome to the COM Application Installation Wizard" window, click "Next>".

  • Click the "Create an empty application" button.

  • Enter your name. Since my DLL name is ASXUpload.dll, so I typed the name "ASXUpload". When Library or Server is specified, select Server.

  • Click the "Next>" button, and then select "This User."

  • Enter a user or click Browse to select a user. Clicking the browse button is safer to provide the correct domain and spelling. Enter the password and confirm the password. If necessary, be sure to specify the domain / username. Click Finish. (Note. We recommend "This user", otherwise someone must be registered on the server to run the DLL.). In my case, I selected a domain administrator account. You can also add a service account. If you are not sure, consult with your system administrator.

  • The Add Application Roles screen appears. Do not add anything, just click the "Next>" button.

  • The Add Users Cast Roles screen appears. Do not add anything, just click the "Next>" button.

  • Now you will see that under “Component Services” → “Computers →“ My Computer ”->“ COM + Application ”-> you will see the newly added application. In this example, the application name will be“ ASXUpload. ”Now expand the newly added application“ ASXUpload "by clicking on the + sign and you will see Components.

  • Now right-click on Components, and then select New Component. In the "Welcome to the COM Application Installation Wizard" window, click "Next>".

  • Click "Install New Features" and now select the DLL that you want to register. In this case, it will be "C: \ MyDLL \ ASXUpload.DLL".

  • After selecting the DLL, you will see that it will show you the components found. Click "Next>" to continue, and finally click "Finish" to complete.

  • Now this is the hard part. Right-click the added application, which you will find under "Component Services" → "Computers → My Computer → COM + Application". In my case, the application name is "ASXUpload". After you right-click on the application, select "Properties". The application properties window opens. Click the "Security" tab. On the "Security" tab, make sure that the "Forced access to check this application" checkbox is not selected in the "Authorization" section.

In the "Security level" section, select the radio button "Perform access check only at the process level. The security property will not be included in the object context. The context of the COM + call will not be available."

Make sure the "Apply restriction policy" option is not set.

Set "Impersonation Level" to "Anonymous"

  1. If you want to access the DLL from a web application, make sure you add an IUSR and IWAM account. To do this, go to COM + application → Application name (in this case it will be ASXUpload) → Roles → CreateOwner → Users. Right-click Users and add the IUSR and IWAM account used by the Internet Information Server.

  2. Also set the NTFS permission in the folder where you store the DLL. In this case, I saved the DLL inside the C: \ MyDLL folder. Now right-click on the "MyDLL" folder and go to the security tab, and then add the IUSR and IWAM account.

This is all you need to do, and you can consume the DLL.

I used this technique twice in two different organizations that I worked with in the past in a production environment, and it works without any problems. At first I tried it in 2005, and then used it again in 2008.

Let me know if you encounter any problems.

+5
source share

We are facing the same problems with the HSBC Cpi interface.

HSBC does not provide a .Net wrapper and the COM wrapper cannot be called from a 64-bit application.

This allows you to deploy it from the 64th server (which probably covers 25% of the new production servers) is almost impossible.

We looked at some of these approaches, but they seemed like a lot of work. In the end, after some, came up with our own implementation, which looks something like this: this.

Use the following Java code to get an intermediate hash

import java.io.Console; import java.lang.*; import java.util.*; import com.clearcommerce.CpiTools.security.HashGenerator; import com.clearcommerce.CpiTools.security.SecCrypto; import javax.xml.bind.annotation.adapters.HexBinaryAdapter; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.security.GeneralSecurityException; import java.util.Vector; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; public class Extract { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try { String encryptedKey = "<YOUR SECRET KEY HERE>"; if (args.length == 1) encryptedKey = args[0]; HexBinaryAdapter hb = new HexBinaryAdapter(); SecCrypto sc = new SecCrypto(); byte abyte0[] = sc.decryptToBinary(encryptedKey); System.out.println("New Secret Base64 Encoded : " + new String(Base64Coder.encode(abyte0))); System.out.println("New Secret Hex Encoded : " + hb.marshal(abyte0)); return; } catch(Exception ex) { System.out.println("Error:" + ex.getMessage()); } } } 

Then use the following .net code to calculate the hash

 using System; using System.Collections.Generic; using System.Text; namespace HsbcIntergration { internal static class CpiHashing { <USE THE VALUE RETURNED FROM THE JAVA CODE HERE> private static readonly byte[] _secret = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; public static string ComputeHash(List<string> inputList) { return ComputeHash(inputList, _secret); } public static string ComputeHash(List<string> inputList, byte[] secretData) { List<string> orderedDataToHash = new List<string>(inputList); orderedDataToHash.Sort(StringComparer.Ordinal); StringBuilder sb = new StringBuilder(); foreach (string s in orderedDataToHash) sb.Append(s); List<byte> dataToHash = new List<byte>(); dataToHash.AddRange(Encoding.ASCII.GetBytes(sb.ToString())); dataToHash.AddRange(secretData); System.Security.Cryptography.HMAC sha = System.Security.Cryptography.HMACSHA1.Create(); sha.Key = secretData; return Convert.ToBase64String(sha.ComputeHash(dataToHash.ToArray(), 0, dataToHash.Count)); } } } 
+2
source share

All Articles