Coldfusion 3DES encrypt使加密结果不同于PHP`mcrypt_encrypt`
首先,Coldfusion加密:Coldfusion 3DES encrypt使加密结果不同于PHP`mcrypt_encrypt`,php,encryption,coldfusion,mcrypt,Php,Encryption,Coldfusion,Mcrypt,首先,Coldfusion加密: <cfset message = '1447841550'> <cfset key = 'Mk9m98IfEblmPfrpsawt7BmxObt98Jev'> <cfset ciphertext = Encrypt(#message#, #key#, "desede", "base64")> <cfoutput>#ciphertext#</cfoutput> $message = "14478415
<cfset message = '1447841550'>
<cfset key = 'Mk9m98IfEblmPfrpsawt7BmxObt98Jev'>
<cfset ciphertext = Encrypt(#message#, #key#, "desede", "base64")>
<cfoutput>#ciphertext#</cfoutput>
$message = "1447841550";
$key = 'Mk9m98IfEblmPfrpsawt7BmxObt98Jev';
$key = base64_decode($key);
$bytes = array(0,0,0,0,0,0,0,0); //byte [] IV = {0, 0, 0, 0, 0, 0, 0, 0}
$iv = implode(array_map("chr", $bytes));
$ciphertext = mcrypt_encrypt(MCRYPT_3DES, $key, $message, MCRYPT_MODE_CBC, $iv);
echo base64_encode($ciphertext);
n6lp0I1w5FxLQHskKMn4sw==
<cfset message = nullPad("1447841550", 8)>
<cfset key = "Mk9m98IfEblmPfrpsawt7BmxObt98Jev">
<!--- Important: IV values should be random, and NOT reused --->
<!--- https://en.wikipedia.org/wiki/Initialization_vector --->
<cfset iv = binaryDecode("0000000000000000", "hex")>
<cfset ciphertext = Encrypt(message, key, "DESede/CBC/NoPadding", "base64", iv)>
<cfoutput>#ciphertext#</cfoutput>
问题。
使用相同的字符串、相同的算法和相同的编码
仍然有一小部分输出不匹配
下面是真实的示例输出
// Coldfusion output.
n6lp0I1w5FwrP3yPw3s8bw==
^^^^^^^^^^
Same part
// PHP output.
n6lp0I1w5FxLQHskKMn4sw==
^^^^^^^^^^
Same part
为什么Coldfusion会产生不同的结果
如何在不修改PHP代码的情况下在Coldfusion中获得相同的结果。
PHP输出对我来说是正确的输出
是否可以使用javascript获得正确的结果(PHP)?这个解决方案也是好的
我很沮丧。设置很接近,但不完全相同。结果不同的原因是:
encrypt()
函数随机生成一个IV。因此,为什么结果不匹配:不同的IV,不同的结果encrypt()
函数不支持零填充。但是,您可以使用类似于此udf的东西来模拟它<cfset message = '1447841550'>
<cfset key = 'Mk9m98IfEblmPfrpsawt7BmxObt98Jev'>
<cfset ciphertext = Encrypt(#message#, #key#, "desede", "base64")>
<cfoutput>#ciphertext#</cfoutput>
$message = "1447841550";
$key = 'Mk9m98IfEblmPfrpsawt7BmxObt98Jev';
$key = base64_decode($key);
$bytes = array(0,0,0,0,0,0,0,0); //byte [] IV = {0, 0, 0, 0, 0, 0, 0, 0}
$iv = implode(array_map("chr", $bytes));
$ciphertext = mcrypt_encrypt(MCRYPT_3DES, $key, $message, MCRYPT_MODE_CBC, $iv);
echo base64_encode($ciphertext);
n6lp0I1w5FxLQHskKMn4sw==
<cfset message = nullPad("1447841550", 8)>
<cfset key = "Mk9m98IfEblmPfrpsawt7BmxObt98Jev">
<!--- Important: IV values should be random, and NOT reused --->
<!--- https://en.wikipedia.org/wiki/Initialization_vector --->
<cfset iv = binaryDecode("0000000000000000", "hex")>
<cfset ciphertext = Encrypt(message, key, "DESede/CBC/NoPadding", "base64", iv)>
<cfoutput>#ciphertext#</cfoutput>
示例:
<cfset message = '1447841550'>
<cfset key = 'Mk9m98IfEblmPfrpsawt7BmxObt98Jev'>
<cfset ciphertext = Encrypt(#message#, #key#, "desede", "base64")>
<cfoutput>#ciphertext#</cfoutput>
$message = "1447841550";
$key = 'Mk9m98IfEblmPfrpsawt7BmxObt98Jev';
$key = base64_decode($key);
$bytes = array(0,0,0,0,0,0,0,0); //byte [] IV = {0, 0, 0, 0, 0, 0, 0, 0}
$iv = implode(array_map("chr", $bytes));
$ciphertext = mcrypt_encrypt(MCRYPT_3DES, $key, $message, MCRYPT_MODE_CBC, $iv);
echo base64_encode($ciphertext);
n6lp0I1w5FxLQHskKMn4sw==
<cfset message = nullPad("1447841550", 8)>
<cfset key = "Mk9m98IfEblmPfrpsawt7BmxObt98Jev">
<!--- Important: IV values should be random, and NOT reused --->
<!--- https://en.wikipedia.org/wiki/Initialization_vector --->
<cfset iv = binaryDecode("0000000000000000", "hex")>
<cfset ciphertext = Encrypt(message, key, "DESede/CBC/NoPadding", "base64", iv)>
<cfoutput>#ciphertext#</cfoutput>
#密文#
在这里解决了吗?嗨,Bardware,我试过了,但结果不一样。我知道我需要应用PHP“MCRYPT_MODE_CBC”中的算法“DESede/ECB/NoPadding”,它不适用于我的“DESede/ECB/NoPadding”或“DESede/ECB/PKCS5Padding”任何想法?对不起,我的意思是DESede/CBC/NoPadding欢迎您。。谢谢你用一个独立的例子提出了一个清晰、简洁的问题。这总是让协助变得更容易:)干杯,欢迎来到S.O。