Giter Club home page Giter Club logo

Comments (4)

brainfoolong avatar brainfoolong commented on August 20, 2024

Hi, your suggested code is not from this project.

from cryptojs-aes-php.

jayjupdhig avatar jayjupdhig commented on August 20, 2024

No?

Here is the original code:

<?php

/**
 * Helper library for CryptoJS AES encryption/decryption
 * Allow you to use AES encryption on client side and server side vice versa
 *
 * @author BrainFooLong (bfldev.com)
 * @link https://github.com/brainfoolong/cryptojs-aes-php
 */

/**
 * Decrypt data from a CryptoJS json encoding string
 *
 * @param mixed $passphrase
 * @param mixed $decrypted
 * @return mixed
 */
function cryptoJsAesDecrypt($decrypted, $passphrase)
{
    list ($decstr, $comb) = explode("*", $decrypted);
    $decstrf = $decstr;

    $combnorm = substr($comb, 0, 48);

    $cnarr = str_split($combnorm, 4);
    $s = $cnarr[0] . $cnarr[2] . $cnarr[4] . $cnarr[6];
    $ivr = $cnarr[1] . $cnarr[3] . $cnarr[5] . $cnarr[7] . $cnarr[8] . $cnarr[9] . $cnarr[10] . $cnarr[11];

    try
    {
        $salt = hex2bin($s);
        $iv = hex2bin($ivr);
    }
    catch (Exception $e)
    {
        return $combnorm;
    }
    $ct = base64_decode($decstrf);
    $concatedPassphrase = $passphrase . $salt;
    $md5 = array();
    $md5[0] = md5($concatedPassphrase, true);
    $result = $md5[0];
    for ($i = 1; $i < 3; $i ++)
    {
        $md5[$i] = md5($md5[$i - 1] . $concatedPassphrase, true);
        $result .= $md5[$i];
    }
    $key = substr($result, 0, 32);
    $data = openssl_decrypt($ct, 'aes-256-cbc', $key, true, $iv);
    if ($data == FALSE)
    {
        return "passphrase:" . $passphrase;
    }
    else
    {
        return json_decode($data, true);
    }

    //return json_decode($data, true);
}

/**
 * Encrypt value to a cryptojs compatiable json encoding string
 *
 * @param mixed $passphrase
 * @param mixed $value
 * @return string
 */
function cryptoJsAesEncrypt($passphrase, $value, $map_id)
{
    $salt = openssl_random_pseudo_bytes(8);
    $salted = '';
    $dx = '';
    while (strlen($salted) < 48)
    {
        $dx = md5($dx . $passphrase . $salt, true);
        $salted .= $dx;
    }
    $key = substr($salted, 0, 32);
    $iv = substr($salted, 32, 16);

    $s = str_split(bin2hex($salt), 4);
    $ivr = str_split(bin2hex($iv), 4);

    $comb = $s[0] . $ivr[0] . $s[1] . $ivr[1] . $s[2] . $ivr[2] . $s[3] . $ivr[3] . $ivr[4] . $ivr[5] . $ivr[6] . $ivr[7];
    $map_iid = $map_id * hexdec($s[0]);

    $encrypted_data = openssl_encrypt(json_encode($value), 'aes-256-cbc', $key, true, $iv);
    $data = array(
        "ct" => base64_encode($encrypted_data) . "*" . $comb . $map_iid,
        "s" => $s,
        "ivr" => $ivr
    );
    return base64_encode($encrypted_data) . "*" . $comb . $map_iid;
}

But i don't know where the programmer has found it...? (I just saw that Eclipse warning while code refactoring)

So the code above is not an older version from your aes library?

from cryptojs-aes-php.

brainfoolong avatar brainfoolong commented on August 20, 2024

No, this is a modified version. You should not use this. It contains some weird things, maybe some custom salts and initialization vectors. Better download the original version from here.

from cryptojs-aes-php.

jayjupdhig avatar jayjupdhig commented on August 20, 2024

Thank you very much!!

from cryptojs-aes-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.