2016-05-25 3 views
2

CloudTraxのためのphpサンプルコード(wifiアクセスポイント)をColdFusionに変換しています。私はコード行に問題があります。 2つのデータ型が連結されています。私は何度も試してみましたが、うまく動作しません。私はPHPが内部的に何をしているのか、内部的にデータを変換して機能させるのかどうかはわかりません。ColdFusion for CloudTraxへのPHP md5の変換

$ hexchall < - バイナリ

秘密< $ - 文字列

PHP

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

CFM

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

Coldfusionが応答します。ByteArrayオブジェクトは文字列に変換できません。 バイナリにCharsetEncode()を使用すると、phpの出力と一致しません。

答えて

1

私はPHPの人ではありませんが、CF側で2つの変数を連結することはできません。両方の値が同じエンコーディングを共有している場合を除き、代わりに、両方の値をバイナリにデコードし、それらをマージしてから、マージした配列をハッシュしてみてください。私はそれが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