Jump to content

Encryption using Triple DES


vidyar_rajan

Recommended Posts

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.  :D

 

Thanks,

Vidya

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • 6 months later...

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

 

Can someone tell what is wrong with the PHP code??

Link to comment
Share on other sites

.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";
        }
    }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.