PHP md5 conversion to Coldfusion for CloudTrax



我正在将CloudTrax(它是一个wifi接入点)的php示例代码转换为ColdFusion。我在一行代码中遇到问题。连接两种数据类型。我已经尝试了多次,但无法让它工作。我不确定 php 在内部做什么,或者它是否在内部转换数据以使其工作。

$hexchall <-二进制

$secret <- 字符串

.PHP

$crypt_secret = md5($hexchall . $secret, TRUE)

.CFM

binaryDecode(lcase(hash(hexchall&secret,"MD5")),"hex")

Coldfusion回应:ByteArray对象无法转换为字符串。如果我在二进制文件上使用CharsetEncode(),它不再与 php 的输出匹配。

我不是 php 人,但我很确定你不能只在 CF 端连接两个变量。除非两个值共享相同的编码,否则不会。 相反,请尝试将这两个值解码为二进制,合并它们,然后对合并的数组进行哈希处理。我怀疑这就是PHP在内部所做的。

确切的代码将根据字符串的编码而有所不同,但这样的东西应该在 CF10+ 中工作。

CF:

// decode both values into binary 
hexchall = binaryDecode("546869732069732062696e617279", "hex");
secret = charsetDecode("this is a secret", "utf-8");
// merge the binary into a single array
// note: arrayAppend will not work with these values
util = createObject("java", "org.apache.commons.lang.ArrayUtils");
mergedBytes = util.addAll(hexchall, secret);
// finally, hash the binary
crypt_secret = lcase(hash( mergedBytes, "md5"));
writeDump(crypt_secret);

.PHP:

$hexchall = hex2Bin("546869732069732062696e617279"); 
$secret = "this is a secret";
$crypt_secret = md5($hexchall. $secret, TRUE);
print_r(bin2hex($crypt_secret));

结果:

2e7840389862afdc913c51df5f394125

最新更新