Professional Web Applications Themes

mcrypt, triple des and java - PHP Development

Hi, I am trying to make a php script give me the same results I am getting from my Java encryption program. The task is to take a key and some text and encrypt it. The java program in essence is: DESede desede = new DESede( seed,-1); String encoded = desede.encode( encodeMe ); System.out.println("EncodeMe: "+encodeMe+ "\nEncoded token:" + encoded ); Output like this: Seed: b166305afb02f2f8b166305afb02f2f8 EncodeMe: |1082474855830|helloworld Encoded token:cWdqJ8GWJ2P5LQuAoGkErIKDsz7V5uzK9YVap9GO3ww= My php code looks like this: $crypted=mcrypt_ecb(MCRYPT_3DES,$key,$toencrypt, MCRYPT_ENCRYPT); and produces this: Crypted : "c^G"q?Cx^[0ѻ~q^ZM???? This is binary data, unprintable. Perhaps I need to uuencode or something to get the output similar ...

  1. #1

    Default mcrypt, triple des and java

    Hi,
    I am trying to make a php script give me the same results I am getting
    from my Java encryption program.

    The task is to take a key and some text and encrypt it. The java program in
    essence is:
    DESede desede = new DESede( seed,-1);
    String encoded = desede.encode( encodeMe );
    System.out.println("EncodeMe: "+encodeMe+ "\nEncoded token:" + encoded );

    Output like this:
    Seed: b166305afb02f2f8b166305afb02f2f8
    EncodeMe: |1082474855830|helloworld
    Encoded token:cWdqJ8GWJ2P5LQuAoGkErIKDsz7V5uzK9YVap9GO3ww=

    My php code looks like this:
    $crypted=mcrypt_ecb(MCRYPT_3DES,$key,$toencrypt, MCRYPT_ENCRYPT);

    and produces this:
    Crypted : "c^G"q?Cx^[0ѻ~q^ZM????

    This is binary data, unprintable. Perhaps I need to uuencode
    or something to get the output similar ?. Not sure why this is not
    required in Java, as the des algorithm should produce the same
    output ?.

    Any clues appreciated.


    Ant Mitchell Guest

  2. #2

    Default Re: mcrypt, triple des and java

    Ant Mitchell spilled the following:
    > I am trying to make a php script give me the same results I am getting
    > from my Java encryption program.
    >
    > The task is to take a key and some text and encrypt it. The java program
    > in essence is:
    <snip - sorry - no speaky java>
    > Output like this:
    > Seed: b166305afb02f2f8b166305afb02f2f8
    > EncodeMe: |1082474855830|helloworld
    > Encoded token:cWdqJ8GWJ2P5LQuAoGkErIKDsz7V5uzK9YVap9GO3ww=
    >
    > My php code looks like this:
    > $crypted=mcrypt_ecb(MCRYPT_3DES,$key,$toencrypt, MCRYPT_ENCRYPT);
    >
    > and produces this:
    > Crypted : "c^G"q?Cx^[0ѻ~q^ZM????
    >
    > This is binary data, unprintable. Perhaps I need to uuencode
    > or something to get the output similar ?.
    Probably, looking at the Java output it looks like base64 encoding cht -
    particularly with the trailing '=' (which PHP does out of the box).

    e.g. colinkermit:~> php -q
    <?php
    // note ths was a cut& paste so some of the non-printable data will have
    // got lost in translation.
    print base64_encode('c^G"q?Cx^[0ѻ~q^ZM????');

    ?>

    Y15HItLYcT9D4njSXlswt/D37LrRu363cV5aTT/Pyz8/Pw==
    colinkermit:~>

    Warning: even if you get the encryption parameters and the encapsulation
    sorted, you may still end up with incompatabilities in the padding. I
    couldn't get ecb working properly using the single line function call and
    ended using an initialization vector etc as shown in the manual, but thats
    propbably more about my incompetence than else.

    HTH

    C.

    Colin McKinnon Guest

Similar Threads

  1. #39498 [NEW]: ext/mcrypt/mcrypt.c hardcoded to use /dev/random
    By mark at exonetric dot com in forum PHP Bugs
    Replies: 3
    Last Post: November 13th, 05:50 PM
  2. triple depedent listbox
    By rajesh in forum Dreamweaver AppDev
    Replies: 2
    Last Post: March 2nd, 06:07 PM
  3. Triple Des encryption/decryption algorithm ....
    By Sai in forum ASP.NET Security
    Replies: 0
    Last Post: August 17th, 07:55 PM
  4. Triple Des
    By Keith Sheehan in forum ASP.NET Security
    Replies: 0
    Last Post: November 5th, 06:15 PM
  5. Help: Triple boot Win XP, Win 98, and Linux (Updated)
    By marius in forum Linux Setup, Configuration & Administration
    Replies: 10
    Last Post: September 3rd, 10:26 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139