we are trying to decrypt an encrypted coldfusion string using AES / OFB / Nopadding in PHP. However, we got an even worse impression, we will try the whole solution here, but still cannot make it work.
here is the code from CF
<cfsetting enablecfoutputonly="Yes"> <cfset k_strCharset="UTF-8"> <cfcontent type="text/html; charset=#k_strCharset#"> <cfset setEncoding("URL", "#k_strCharset#")> <cfset setEncoding("FORM", "#k_strCharset#")> <cfif IsDefined("FORM.K1")><cfset fv_strK1="#FORM.K1#"><cfelse><cfset fv_strK1=""></cfif> <cfif IsDefined("FORM.S1")><cfset fv_strS1="#FORM.S1#"><cfelse><cfset fv_strS1=""></cfif> <cfif IsDefined("FORM.S2")><cfset fv_strS2="#FORM.S2#"><cfelse><cfset fv_strS2=""></cfif> <cfif fv_strK1 is "xxx"> <cfif fv_strS1 is not ""> <cfset fv_strS2 = Encrypt(fv_strS1, fv_strK1, "AES/OFB/NoPadding", "BASE64")> <cfelseif fv_strS2 is not ""> <cfset fv_strS1 = Decrypt(fv_strS2, fv_strK1, "AES/OFB/NoPadding", "BASE64")> </cfif> <cfset fv_strS3 = ""> <cfset fv_strS4 = ""> <cfset fv_strS5 = ""> </cfif> <cfsetting enablecfoutputonly="No">
then we do php like
<?php $z = "bf19zWnbPmJxOvzRuP85Bw=="; $encrypted_string="q2SYE7hWWltsBw5byuwl/IkGmOOm+94="; $source_text = html_entity_decode(getDecrypt($encrypted_string, $z), ENT_NOQUOTES, 'UTF-8'); //echo trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_OFB)); echo "<br>" . $z . "<br>"; // echo trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, base64_decode($z), base64_decode($encrypted_string), MCRYPT_MODE_OFB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_OFB), MCRYPT_RAND))); echo "\n\nPlain-Text:\n" . $source_text . "\n"; // Functions function getDecrypt($str, $key) { return ofb_decrypt(base64_decode($str),$key); } function ofb_decrypt($str, $key, $iv = ' ' ) { if ($iv==' ' & strlen($str) < 16) return false; $td = mcrypt_module_open(MCRYPT_RIJNDAEL_128, ' ' , MCRYPT_MODE_NOFB, ' '); //RECEOVER IV $iv_size = mcrypt_enc_get_iv_size($td); if (empty($iv)) { $iv = substr($str,0,$iv_size); $str = substr($str,$iv_size); } // initialize encryption mcrypt_generic_init($td, $key, $iv); // decrypt $decrypted_string = mdecrypt_generic($td, $str); // terminate decrtypion mcrypt_generic_deinit($td); mcrypt_module_close($td); return $decrypted_string; } ?>
$ encrypted_string is created using the CF script above.
then we got the result: = @ & O% NSC # p:
Really appreciate if anyone can give me a hint.
Thank you