Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13
  1. #1
    Junior Member
    Join Date
    Aug 2019
    Posts
    13
    Member #
    60890

    What is wrong decoding this Base64 string?

    In the beginning, a unicode string containing the phrase: "string coming from the client..." encrypted with AES256 CBC and then passed from Base64 encoding to become text. That text is put in the php file to decrypt it. I have the following code that does the job. The point is that no string is returned. Has it to do with the use of unicode?
    $key and $iv are exactly tha same used for encryption.
    PHP Code:
    <!doctype html>
    <html>
    <head>
    <meta charset="UTF-8">
    </head>
    <body>

    <?php

    function fnDecrypt($sValue$sSecretKey$iv) {
        return 
    rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256$sSecretKeybase64_decode($sValue),  MCRYPT_MODE_CBC$iv), "\0\3");
    }

    $key "12345678901234567890123456789012";
    $iv "09876543210987654321098765432100";
    $str "/F/9WXb7y6j1tOcKTmFy608wO2BFo8jZ1HUo4+oPUG9AQ/UyY1KxVcVbNfDtRNAQdIqseKNuK5DPpkhooAxVBAAA";

    $newStr fnDecrypt($str$Key$iv);
    echo 
    "<br/>str = " $str;
    echo 
    "<br/>new = " $newStr;


    ?>

    </body>
    </html>

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,714
    Member #
    5580
    Liked
    717 times
    I think you have to encrypt it first.
    Then you can decrypt it to make sure it comes back as original.

    You are only decrypting it.


    Like this example to encrypt and decrypt ...
    PHP Code:
    <?php
    $key 
    '12345678901234567890123456789012';
    $string ' string to be encrypted '// note the spaces

    $encrypted base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256md5($key), $stringMCRYPT_MODE_CBCmd5(md5($key))));
    $decrypted rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256md5($key), base64_decode($encrypted), MCRYPT_MODE_CBCmd5(md5($key))), "\0");

    echo 
    'Encrypted:' "\n";
    var_dump($encrypted);

    echo 
    "\n";

    echo 
    'Decrypted:' "\n";
    var_dump($decrypted); // spaces are preserved

    ?>


  4. #3
    Junior Member
    Join Date
    Aug 2019
    Posts
    13
    Member #
    60890
    But in mcrypt_decrypt() I do use base64_decode(), so the string is decoded before decryption. Am I wrong?

  5. #4
    Junior Member
    Join Date
    Aug 2019
    Posts
    13
    Member #
    60890
    And yes, I only want to decrypt it. Encryption has already be done outside the php file.

  6. #5
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,714
    Member #
    5580
    Liked
    717 times
    I guess this whole thing is getting out of my area of expertise.
    You may have to ask in a different forum.


  7. #6
    Junior Member
    Join Date
    Aug 2019
    Posts
    13
    Member #
    60890
    Do you know any forum to ask? I did a Google search and found two dead forums only. (By saying "dead", I mean the last post seems to be written some years ago.)

  8. #7
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,714
    Member #
    5580
    Liked
    717 times
    Try www.codingforums.com

    Specifically ask in the PHP section.
    I will warn you that what you're doing is probably not the "preferred" way of handling what you are attempting to do. It doesn't matter to me, and I would help if I know more about it. But the experts you ask may get a little snarky or condescending. They are very knowledgeable though and know the most about how to properly script with PHP.

    Post exactly what you did in the first post (#1) and show your script too.
    We'll see what they say.

    I also use www.codingforums.com and I use the same username as this forum.

    I've been beat-up a few times on codingforums.com, but I have learned a lot, and I pay attention to what the experts tell me. I've learned to not take to too seriously.


  9. #8
    Junior Member
    Join Date
    Aug 2019
    Posts
    13
    Member #
    60890
    What would be the 'right' way for them? The forum you mention seems like stackoverflow.com, where, if I new most of the admins, I would kill them with my bare hands.

  10. #9
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,714
    Member #
    5580
    Liked
    717 times
    LOL!
    I would like that ... the blood would be on your hands, not mine

    I don't know the "right" way, I just assume they will mention some other encryption method.
    Go ahead and ask them anyhow, maybe you'll get lucky.

    Some of the sections on CF are monitored by people that really do help, like the CGI (Perl) section.

    It's the professional programmers (PHP, Python) that expect couch programmers like us to be experts in the languages. I even had one private message me and ask me why I was helping people without knowing what I was doing. I almost got banned, but I have so many posts on the CF forum that they didn't know what to do with me. I find it sort of entertaining.

    And when I started on this forum in 2004, I was mysteriously given "staff" level. So now I can edit and ban users. Nobody here really knows who the owner of WDF is. We just keep it running and ban spammers/robots. We try to have fun and for sure don't want to flame anyone. I'm certainly not a professional programmer. I'm more of an electronics hardware guy.
    Last edited by mlseim; Aug 15th, 2019 at 01:59 PM.


  11. #10
    Junior Member
    Join Date
    Aug 2019
    Posts
    13
    Member #
    60890
    In the next few days I will have some serious code written and I will post it there begging for mercy. (lol)

    My profession is not programming, I am a primary school teacher and programming is my hobby. I like building apps that I need/was asked to build. This book app was asked by the library admin, school's library, as couldn't find any that was working as she wanted to work. On the other hand, national school network has servers doing some basic work for hosting, AFAIK there is no staff at the moment as the government hasn't renewed their contracts since January 1st (there are 2-3 of them trying to do some very basic work, just to keep those servers online)q, and here is me trying to create an app that communicates with those servers, and I don't know much about servers. I only know some basic theoretical things. Have a good day my friend!


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:55 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com