我们遇到了与HSBC Cpi接口相同的问题。
汇丰银行不提供.NET包装,和COM包装 不能从64位应用程序调用。
这使得从64服务器(这可能 占地面积新的生产服务器25%)几乎IMPOSIBLE上部署它。
我们看了一些上市的途径,但他们似乎 了很多工作。最后经过一番讨论后,我们 想出了我们自己的实现,这看起来像 这个。
使用下面的Java代码来获取中间值散列
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());
}
}
}
然后使用下面的.NET代码calcualte哈希
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));
}
}
}
感谢克里斯这个作品。 不幸的是汇丰不支持64位操作系统。 – 2009-04-20 14:25:51