SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using PHP's RC4Crypt to Interpret Data Encrypted by Meychi's RC4 (ASCrypt)

    I'm sending encrypted data from Flash to PHP using LoadVars. While still in Flash, I'm using the RC4 class of Meychi's ASCrypt package to encrypt said data. The encrypted data is being received by PHP successfully, and my key is correct. I'm having trouble decrypting the data, though. I think the root of my problem comes down to the nature of the arguments (hexadecimal v. binary). After some playing around, I've been able to reproduce ASCrypt's output using PHP's RC4Crypt, but I still can't seem to figure out how to decrypt it.

    Here's a PHP script I've made that reproduces the encrypted data coming from Flash. Could anyone show me how to go about decrypting it???


    Code:
    require_once("scripts" . "/" . "rc4crypt" . "." . "php");
    
    $data = "The secret message is flewdendybewdendybop.";
    $key = "1234567890";
    
    $encryptedData = bin2hex(rc4crypt::encrypt($key, $data, 0));
    //The next part is what needs fixed
    $decryptedData = rc4crypt::decrypt($key, $encryptedData, 0);
    
    echo "<b>data:</b><br />$data<br /><br />";
    echo "<b>key:</b><br />$key<br /><br />";
    echo "<b>encryptedData:</b><br />$encryptedData<br /><br />";
    echo "<b>decryptedData:</b><br />$decryptedData<br /><br />";

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    You have to turn the encrypted data from hex to binary. I assume.
    pack('H*', $hex_str) can be used to turn it into binary.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Member
    Join Date
    May 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    $data = "The secret message is flewdendybewdendybop.";
    $key = "1234567890";
    
    $encryptedData = bin2hex(rc4crypt::encrypt($key, $data, 0));
    $decryptedData = rc4crypt::decrypt($key, pack('H*', $encryptedData), 0);
    It worked perfectly. Thanks so much!


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
  •