vidyar_rajan Posted March 6, 2007 Share Posted March 6, 2007 hi guys, currently i am working on a project where we are encrypting a string using triple DES. this encrypted is used for decryting in VC++(this is done by the client) can anyone tell me different ways of performing triple DES encryption. Please reply ASAP thank you in advance. Thanks, Vidya Quote Link to comment https://forums.phpfreaks.com/topic/41400-encryption-using-triple-des/ Share on other sites More sharing options...
btherl Posted March 6, 2007 Share Posted March 6, 2007 This can get you started http://sg.php.net/manual/en/ref.mcrypt.php "This is an interface to the mcrypt library, which supports a wide variety of block algorithms such as DES, TripleDES, Blowfish (default), 3-WAY, SAFER-SK64, SAFER-SK128, TWOFISH, TEA, RC2 and GOST in CBC, OFB, CFB and ECB cipher modes." Is your question "How do I implement 3DES in php", or are you asking more generally about how 3DES can be used? Quote Link to comment https://forums.phpfreaks.com/topic/41400-encryption-using-triple-des/#findComment-200542 Share on other sites More sharing options...
achuthanz Posted September 21, 2007 Share Posted September 21, 2007 I have a similar problem where my 3DES encrypted string using PHP needs to be decrypted by a .NET class using CryptoStream. But, the output of encryption between the php code and .NET class are not matching. PHP: $string = 'To encrypt'; echo '<b>Original String:</b>'.$string.'<br>'; $td = mcrypt_module_open (MCRYPT_TRIPLEDES, '', MCRYPT_MODE_CBC, ''); $ks = mcrypt_enc_get_key_size ($td); $key = substr ('abcdefghijklmnop', 0, $ks); $key = utf8_encode($key); $iv = 'zyxwvuts'; $iv = utf8_encode($iv); mcrypt_generic_init ($td, $key, $iv); $encryptedString = mcrypt_generic ($td, utf8_encode($string)); mcrypt_generic_deinit ($td); echo '<b>Encrypted:</b>'.base64_encode($encryptedString).'<br>'; mcrypt_generic_init ($td, $key, $iv); $decryptedString = mdecrypt_generic ($td, $encryptedString); echo '<b>Decrypted:</b>'.trim($decryptedString).'<br>'; mcrypt_generic_deinit ($td); mcrypt_module_close ($td); .NET http://msdn2.microsoft.com/en-us/library/aa302405.aspx Can someone tell what is wrong with the PHP code?? Quote Link to comment https://forums.phpfreaks.com/topic/41400-encryption-using-triple-des/#findComment-352428 Share on other sites More sharing options...
MadTechie Posted September 21, 2007 Share Posted September 21, 2007 .Net using padding, php doesn't try this check the .Net and set the padding to Zeros TripleDES tdes = TripleDES.Create(); tdes.Padding = PaddingMode.Zeros; then pad the php version $buffer = $_POST['data']; // get the amount of bytes to pad $extra = 8 - (strlen($buffer) % ; // add the zero padding if($extra > 0) { for($i = 0; $i < $extra; $i++) { $buffer .= "\0"; } } Quote Link to comment https://forums.phpfreaks.com/topic/41400-encryption-using-triple-des/#findComment-352437 Share on other sites More sharing options...
achuthanz Posted September 21, 2007 Share Posted September 21, 2007 Nope. That isn't working. The results are still different.. Quote Link to comment https://forums.phpfreaks.com/topic/41400-encryption-using-triple-des/#findComment-352500 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.