功能是实现MAC算法,下面是Java版本的,用到了DES,如果大家有delphi版本的MAC算法,贴上,就不用翻译底下的java版本了,如果没的话,帮忙翻译一下,其中涉及Des部分(红色部分),就不需要翻译了。谢谢/**
 * 实现ECB加密,返回16位十六进制MAC码,如果出现异常返回null
 * 
 * @param input
 *            明文
 * @param key
 *            密钥十六进制(明文)
 * @return 8位MAC码
 */
public String ecbEncrypt(String input, String key) {
byte[] mac = new byte[8];
byte[] temp = new byte[8];
int z = 0;
try {
byte[] bt = input.getBytes("iso-8859-1");
int len = bt.length;
int other = len % 8;
// 如果密文最后不足8个字节,则以0补足
if (other != 0) {
byte[] tt = bt;
bt = new byte[tt.length + (8 - other)];
System.arraycopy(tt, 0, bt, 0, len);
} // 初始化mac数组,最明文的前8个字节,用来进行循环异或
for (int i = 0; i < 8; i++) {
mac[i] = bt[i];
}
// 循环异或
for (int i = 8; i <= bt.length; i++, z++) {
if (i != 8 && i % 8 == 0) {
for (int j = 0; j < 8; j++) {
mac[j] = (byte) (mac[j] ^ temp[j]);
}
z = 0;
temp = new byte[8];
}
if (i != bt.length) {
temp[z] = bt[i];
}
}
byte[] tmpResult = new byte[8];// 用来存放异或结果
tmpResult = des(mac, String2Hex(key));

return Hex2String(tmpResult).toUpperCase();
} catch (Exception e) { return null;
}
}