×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    1

    crypting with J2ME decrypting with PHP

    Hallo,

    i'm working on an encryption methode for post-streams.
    my J2ME device encrypt my content (using bouncy castle api) and send it to a php script which decrypt the post-stream. But my php script decrypt it into something useless.

    -----------J2ME CODE-------------------------------------
    private String key = "1234567890";
    private String text = "Crypt this";

    private String encryptText(String key, String text) throws CryptoException
    {
    byte[] keyBytes = Base64.decode(key.getBytes());
    byte[] ptBytes = text.getBytes();

    bfCipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new BlowfishEngine()));
    bfCipher.init(true, new KeyParameter(keyBytes));
    byte[] result = new byte[bfCipher.getOutputSize(ptBytes.length)];
    int len = bfCipher.processBytes(ptBytes, 0, ptBytes.length, result, 0);
    bfCipher.doFinal(result, len);

    return new String(Base64.encode(result));
    }//encryptText

    private String decryptText(String key, String cipherText) throws CryptoException
    {
    byte[] keyBytes = Base64.decode(key.getBytes());
    byte[] textBytes = Base64.decode(cipherText.getBytes());

    bfCipher.init(false, new KeyParameter(keyBytes));
    byte[] result = new byte[bfCipher.getOutputSize(textBytes.length)];
    int len = bfCipher.processBytes(textBytes, 0, textBytes.length, result, 0);
    bfCipher.doFinal(result, len);

    return new String(result).trim();
    }//decryptText
    ----------------------------------------------------------------
    PHP CODE:

    <?php
    if (isset($_POST["test"])) { $test = $_POST["test"]; }

    $iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, MCRYPT_MODE_CBC);
    $iv = "ha123"; //this isn't used in J2ME, don't know where to
    //implement it
    $key = "1234567890";
    function strhex($string)
    {
    $hex="";
    for ($i=0;$i<strlen($string);$i++)
    $hex.=dechex(ord($string[$i]));
    return $hex;
    }
    $textkey = strhex($key);
    echo " hexkey: $textkey ";

    echo " bevor: $test ";
    $decrypt = mcrypt_decrypt(MCRYPT_BLOWFISH, $textkey, $test, MCRYPT_MODE_CBC, $iv);
    echo " decrypt: $decrypt ";
    flush();

    ?>

    I hope you've an idea.
    Thx for helping.

  2. #2
    Registered User
    Join Date
    Jan 2009
    Posts
    2

    Re: crypting with J2ME decrypting with PHP

    your PHP decryption code should be like-

    $key = "273e1557de5e4499";
    $B64key=base64_decode($key);
    $B64data_string=base64_decode($data_string);
    $decrypt = @mcrypt_decrypt(MCRYPT_BLOWFISH, $B64key , $B64data_string, MCRYPT_MODE_CBC);
    echo " <br /> decrypted data = $decrypt ";


    hope you've an idea.

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    270

    Re: crypting with J2ME decrypting with PHP

    I haven't understand what I need to set as "key" for the javaME side and the PHP one.

    Can you help me please?

  4. #4
    Registered User
    Join Date
    Nov 2006
    Posts
    270

    Re: crypting with J2ME decrypting with PHP

    I fixed the interesting lines, now it works like a charm on every input.

    J2ME Code

    Code:
     
       private String key = "SADFo92jzVnzSj39IUYGvi6eL8v6RvJH8Cytuiouh547vCytdyUFl76R";
        private String text = "Crypt this";
        PaddedBufferedBlockCipher bfCipher;
    
        private String encryptText(String key, String text) throws CryptoException {
            byte[] keyBytes = Base64.decode(key.getBytes());
            byte[] ptBytes = text.getBytes();
    
            bfCipher = new PaddedBufferedBlockCipher (new CBCBlockCipher(new BlowfishEngine()), new ZeroBytePadding());
            bfCipher.init(true, new KeyParameter(keyBytes));
            byte[] result = new byte[bfCipher.getOutputSize(ptBytes.length)];
            int len = bfCipher.processBytes(ptBytes, 0, ptBytes.length, result, 0);
            bfCipher.doFinal(result, len);
    
            return new String(Base64.encode(result));
        }//encryptText
    
        private String decryptText(String key, String cipherText) throws CryptoException {
            byte[] keyBytes = Base64.decode(key.getBytes());
            byte[] textBytes = Base64.decode(cipherText.getBytes());
    
            bfCipher.init(false, new KeyParameter(keyBytes));
            byte[] result = new byte[bfCipher.getOutputSize(textBytes.length)];
            int len = bfCipher.processBytes(textBytes, 0, textBytes.length, result, 0);
            bfCipher.doFinal(result, len);
    
            return new String(result).trim();
        }//decryptText

    PHP CODE:

    Code:
    $key = "SADFo92jzVnzSj39IUYGvi6eL8v6RvJH8Cytuiouh547vCytdyUFl76R";
    $B64key=base64_decode($key);
    $B64data_string=base64_decode($data_string);
    $decrypt = @mcrypt_decrypt(MCRYPT_BLOWFISH, $B64key , $B64data_string, MCRYPT_MODE_CBC);
    echo " <br /> decrypted data = $decrypt ";
    Hope it helped.

  5. #5
    Regular Contributor
    Join Date
    May 2010
    Posts
    64

    Re: crypting with J2ME decrypting with PHP

    Hi,

    I am trying to learn about encryption in phone and decryption on the web (server or php). Good that I came across to this post.

    As long as I can get from the discussion, there is something about the key. So, why did SADFo92jzVnzSj39IUYGvi6eL8v6RvJH8Cytuiouh547vCytdyUFl76R work and 1234567890 didnot?

  6. #6
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: crypting with J2ME decrypting with PHP

    Good day !!

    this is what ive looking for ..
    im a new begginer in java then we have a project ..

    i have my message that was encrypted in j2me then it will send in php .
    i want to decrypt it by php can you please help me on it ..

    what codes can you offer to me ?

    thanks in regard.
    god Bless more power !

  7. #7
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,698

    Re: crypting with J2ME decrypting with PHP

    Well, for codes, you may want to consider reading post #4 in this discussion. Of course decryption depends a lot on the actual way you encrypt the data.

  8. #8
    Registered User
    Join Date
    Nov 2006
    Posts
    270

    Re: crypting with J2ME decrypting with PHP

    Quote Originally Posted by wizard_hu_ View Post
    Well, for codes, you may want to consider reading post #4 in this discussion. Of course decryption depends a lot on the actual way you encrypt the data.
    it's incredible that in 2012 there is someone who talk about JavaME.

  9. #9
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: crypting with J2ME decrypting with PHP

    hello good day ..

    sir so it is possible that using a encrypted data by j2me you can decrypt it by php is there any code for this .

    thanks in regard.

    God bless !!1 more power ..

  10. #10
    Super Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,563

    Re: crypting with J2ME decrypting with PHP

    Quote Originally Posted by AnorEnaj2330 View Post
    sir so it is possible that using a encrypted data by j2me you can decrypt it by php is there any code for this .
    Yes, as I have told you elsewhere in these forums, it is possible to encrypt data by J2ME and decrypt by PHP as long as you are using the same encryption/decryption algorithms (cipher) and keys on both sides.

    Incidentally, that's also evident by reading the earlier replies in this very same thread, because that's what it is about.

    You also keep asking for "code". More or less all the examples and links you've been pointed to already has "code". You seem to be looking for a ready-made solution for your school assignment, so that you don't need to learn or understand what needs to be done yourself. That's not a very good way to learn. Take the examples you already have been provided through this thread and elsewhere (your other discussions, wiki and web site examples and articles on the subject), create your own version of the code for your project based on those, and if you have specific problems with your version of the code, come back with your code, and explain what you expect to happen with your code, what actually happens (including any errors and sample data), and maybe someone can tell you what you're doing wrong. If you can't do that, then a line of studies where you're supposed to write code is probably not the right direction for you, or for your future profession.

  11. #11
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: crypting with J2ME decrypting with PHP

    Good day !

    Sir i have my downloaded file.
    heres the jar and jad file sir.

    http://cryptosms.org/ota/

    the the receiver is php application

    do we need to install the program there?
    or it can decrypt by php automatically tnx .

    god bless ! tnx in regard.
    Last edited by AnorEnaj2330; 2012-10-01 at 02:59.

  12. #12
    Super Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,563

    Re: crypting with J2ME decrypting with PHP

    There are probably better (and more easily adaptable for your needs) examples already in this thread, and the other locations you've been directed to, than an SMS example.

    The only automatic way for PHP to decrypt the data is, if - as I've suggested to you a few times before - is, if you use HTTPS. If you don't want to use HTTPS, you need write code for *BOTH* the phone *AND* the server.

    In any case, I think that short of writing your app for you (which I'm not going to do), I think I've done all I can. I suggest that you also re-read what I wrote above:

    Take the examples you already have been provided through this thread and elsewhere (your other discussions, wiki and web site examples and articles on the subject), create your own version of the code for your project based on those, and if you have specific problems with your version of the code, come back with your code, and explain what you expect to happen with your code, what actually happens (including any errors and sample data), and maybe someone can tell you what you're doing wrong. If you can't do that, then a line of studies where you're supposed to write code is probably not the right direction for you, or for your future profession.
    Good luck.

  13. #13
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: crypting with J2ME decrypting with PHP

    can you give me some standard decrypter for all applications
    because i can't find a standard dercyption and encryption for all application .

    thanks.

  14. #14
    Super Contributor
    Join Date
    Mar 2003
    Location
    Finland
    Posts
    9,563

    Re: crypting with J2ME decrypting with PHP

    Quote Originally Posted by AnorEnaj2330 View Post
    can you give me some standard decrypter for all applications
    because i can't find a standard dercyption and encryption for all application .
    Reply #4 in this very same thread above has J2ME code to encrypt data using the Blowfish cipher, and the same reply has PHP code to decrypt the data also using the same Blowfish cipher. So, scroll the page up, and take the code from there.

  15. #15
    Registered User
    Join Date
    Jul 2012
    Location
    South America
    Posts
    43

    Re: crypting with J2ME decrypting with PHP

    Good day sir this is my codes.
    and i want to secure my messages that i will send to the receiver.

    sir what should i do the reply #4 is not working .
    i want to use blowfish but i dont know how to use it.


    public void commandAction(Command cmd,Displayable disp) {
    if(cmd==exit) {
    destroyApp(false);
    }
    if(cmd==send) {
    String mno=toWhom.getString();
    String msg=message.getString();
    if(mno.equals("")) {
    alert = new Alert("Alert !!!");
    alert.setString("Enter Mobile Number!!!");
    alert.setTimeout(2000);
    display.setCurrent(alert);
    }
    else {
    try {
    clientConn=(MessageConnection)Connector.open("sms://"+mno);
    }
    catch(Exception e) {
    alert = new Alert("Alert !!! ");
    alert.setString("Message Sent");
    alert.setTimeout(2000);
    display.setCurrent(alert);
    }
    try {
    TextMessage textmessage = (TextMessage) clientConn.newMessage(MessageConnection.TEXT_MESSAGE);
    textmessage.setAddress("sms://"+mno);
    textmessage.setPayloadText(msg);

    clientConn.send(textmessage);
    }
    catch(Exception e)
    {
    Alert alert=new Alert("Alert","",null,AlertType.INFO);
    alert.setTimeout(Alert.FOREVER);
    alert.setString("Unable to send");
    display.setCurrent(alert);
    }
    }
    }
    }
    }

Posting Permissions

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