简体   繁体   English

PHP mcrypt到ColdFusion解密

[英]PHP mcrypt to ColdFusion decrypt

I am working in a PHP app we have a particular string that we need to encrypt before storing in a database. 我在PHP应用程序中工作,我们有一个特定的字符串,我们需要在存储到数据库之前加密。 I can do this in PHP with not problem using mcrypt with a key and a iv. 我可以在PHP中使用带有密钥和iv的mcrypt没有问题。 Currently I'm trying to use blowfish because I thought it would be the most flexible as far as decrypting it in ColdFusion. 目前我正在尝试使用blowfish因为我认为在ColdFusion中解密它会是最灵活的。 The issue I ran into is it seems ColdFusion doesn't want to use the key or iv I encrypted with. 我遇到的问题是看起来ColdFusion似乎不想使用密钥或iv加密。 ColdFusion wants you to generateSecretKey() and use some other way to create the iv. ColdFusion希望你使用generateSecretKey()并使用其他方法来创建iv。

What I can't seem to do is get the two to communicate. 我似乎无法做的是让两人沟通。 I tried first encrypting in coldFusion and using the key it generated and iv it used in PHP but the result was not what it should be. 我首先尝试在coldFusion中加密并使用它生成的密钥,然后在PHP中使用它,但结果并非如此。 I know I must be missing something but I can't quite pinpoint what it might be. 我知道我必须遗漏一些东西,但我无法确定它可能是什么。

<?php
$securedString = mcrypt_encrypt ('MCRYPT_BLOWFISH' , 'THISISMYKEYTHATISVERYLONG32CHARS' , "This is the string I need encrypted' , MCRYPT_MODE_CBC , '12345678');
echo base64_encode($securedString);
?>

So what would an equivalent ColdFusion Decryption call look like? 那么等效的ColdFusion解密调用会是什么样的呢?

BTW: if Blowfish is not the ideal algorithm to use please feel free to suggest another as long as both ColdFusion and PHP can use it and it is secure. 顺便说一句:如果Blowfish不是理想的算法,只要ColdFusion和PHP都可以使用它并且它是安全的,请随意建议另一个。

Thanks, Bruce 谢谢,布鲁斯

Something like this should work. 这样的事情应该有效。 You just need to share a common key between each. 您只需要在每个之间共享一个公共密钥。

In PHP: 在PHP中:

base64_encode(mcrypt_encrypt(MCRYPT_3DES, $key, $plain_string, MCRYPT_MODE_ECB));

In Coldfusion: 在Coldfusion中:

<cfscript>
     decrypted_string = decrypt(enc_string, key, "DESEDE", "Base64");
</cfscript>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM