(对于 cmets 来说太长了)
Artjom B. already provided the answer above。 Artjom B. 写道
问题是填充。 PHP 的 mcrypt 扩展只使用
ZeroPadding [...] 您要么需要在 php [...] 中填充明文,要么
在 ColdFusion 中使用不同的密码,例如“DES/ECB/NoPadding”。一世
推荐前者,因为如果使用NoPadding,明文必须
已经是块大小的倍数。
不幸的是,在 CF 中很难生成null character。 AFAIK,唯一有效的技术是use URLDecode("%00")。如果您无法按照@Artjom B. 的建议修改 PHP 代码,您可以尝试使用下面的函数来填充 CF 中的文本。免责声明:它只是经过轻微测试(CF10),但似乎产生与上述相同的结果。
更新:
由于CF encrypt()函数always interprets the plain text input as a UTF-8 string,还可以使用charsetEncode(bytes, "utf-8")从单元素字节数组中创建空字符,即charsetEncode( javacast("byte[]", [0] ), "utf-8")
示例:
Valor = nullPad("TESTE", 8);
Key = "$224455@";
result = Encrypt(Valor, ToBase64(Key), "DES/ECB/NoPadding", "BASE64");
// Result: TzwRx5Bxoa0=
WriteDump( "Encrypted Text = "& Result );
功能:
/*
Pads a string, with null bytes, to a multiple of the given block size
@param plainText - string to pad
@param blockSize - pad string so it is a multiple of this size
@param encoding - charset encoding of text
*/
string function nullPad( string plainText, numeric blockSize, string encoding="UTF-8")
{
local.newText = arguments.plainText;
local.bytes = charsetDecode(arguments.plainText, arguments.encoding);
local.remain = arrayLen( local.bytes ) % arguments.blockSize;
if (local.remain neq 0)
{
local.padSize = arguments.blockSize - local.remain;
local.newText &= repeatString( urlDecode("%00"), local.padSize );
}
return local.newText;
}