在Coldfusion中加密,然后在PHP中解密

我有一个问题,复制 PHP和Coldfusion中生成的相同结果.

PHP加密这种方式:

<?PHP
    $key = "$224455@";
    $Valor = "TESTE";

    $base = chop(base64_encode(mcrypt_encrypt(MCRYPT_DES,$key,$Valor,MCRYPT_MODE_ECB)));     
?>

我有结果:

TzwRx5Bxoa0=

在Coldfusion这样做:

<cfset Valor = "TESTE">
<cfset Key = "$224455@">
<cfset base = Encrypt(Valor,ToBase64(Key),"DES/ECB/PKCS5Padding","BASE64")>

结果:

qOQnhdxiIKs=

什么不是ColdFusion产生与PHP相同的价值?

非常感谢你

(评论太长)

Artjom B. already provided the answer above. Artjom B.写道

The problem is the padding. The mcrypt extension of PHP only uses
ZeroPadding […] you either need to pad the plaintext in PHP […] or
use a different cipher in ColdFusion such as “DES/ECB/nopadding”. I
recommend the former,because if you use nopadding,the plaintext must
already be a multiple of the block size.

不幸的是,很难在CF中生产null character. AFAIK,唯一有效的技术是use URLDecode("%00").如果你不能修改PHP代码为@Artjom B.建议,你可以尝试使用下面的函数填充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,"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;
}

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...