Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The aes.js use gibberish-aes (with md5) #122

Open
GoogleCodeExporter opened this issue Apr 1, 2015 · 2 comments
Open

The aes.js use gibberish-aes (with md5) #122

GoogleCodeExporter opened this issue Apr 1, 2015 · 2 comments

Comments

@GoogleCodeExporter
Copy link

I would like to use this hash with sha256 or sha512. Can you help me?

Original issue reported on code.google.com by thenextw...@gmail.com on 30 Mar 2014 at 11:52

@GoogleCodeExporter
Copy link
Author

*hash = encryption (Sorry, I misspelled.)

Original comment by thenextw...@gmail.com on 30 Mar 2014 at 11:54

  • Added labels: ****
  • Removed labels: ****

@GoogleCodeExporter
Copy link
Author

Example with php:

function encrypt($data, $password) {
    // Set a random salt
    $salt = openssl_random_pseudo_bytes(8);

    $salted = '';
    $dx = '';
    // Salt the key(176) and iv(16) = 192
    while (strlen($salted) < 192) {
      $dx = hash(sha512, $dx.$password.$salt, true);
      $salted .= $dx;
    }

    $key = substr($salted, 0, 176);
    $iv  = substr($salted, 176,16);

    $encrypted_data = openssl_encrypt($data, 'aes-256-cbc', $key, true, $iv);
    return base64_encode('Salted__' . $salt . $encrypted_data);
  }

function decrypt($edata, $password) {
    $data = base64_decode($edata);
    $salt = substr($data, 8, 8);
    $ct = substr($data, 16);

    $rounds = 3;
    $data00 = $password.$salt;
    $sha512_hash = array();
    $sha512_hash[0] = hash(sha512, $data00, true);
    $result = $sha512_hash[0];
    for ($i = 1; $i < $rounds; $i++) {
      $sha512_hash[$i] = hash(sha512, $sha512_hash[$i - 1].$data00, true);
        $result .= $sha512_hash[$i];
    }
    $key = substr($result, 0, 176);
    $iv  = substr($result, 176,16);

      return openssl_decrypt($ct, 'aes-256-cbc', $key, true, $iv);
  }

Original comment by thenextw...@gmail.com on 30 Mar 2014 at 8:02

  • Added labels: ****
  • Removed labels: ****

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant