Skip to content

Instantly share code, notes, and snippets.

@radiosilence
Created May 2, 2011 18:02
Show Gist options
  • Select an option

  • Save radiosilence/952042 to your computer and use it in GitHub Desktop.

Select an option

Save radiosilence/952042 to your computer and use it in GitHub Desktop.
<?php
$msg = "Lorem";
// Key that user inputs
$okey = "potato";
// A slow hash is made from this key - 2^14 iterations of whirlpool. Salt is generated automatically and is about 100 characters long.
$hash = $hasher->hash($okey);
// Salt of this hash is taken and stored, so that hash can be re-created with correct original key.
$salt = $hasher->pull_salt($hash);
// Last 32 characters of hash are taken for use as actual key
$key = substr($hash, -32);
// Encrypted with RIJNDAEL-256
$enc = $c->encrypt($msg, $key, True);
// DECRYPTION
$attempt = "potato"
var_dump("DERIVED HASH", $hash, "STORED DATA:", $enc, $salt, "REQUIRED DATA:", $okey, "ACTUAL KEY", $key2, "MESSAGE:",
$c->decrypt($enc, substr($hasher->hash($attempt, $salt), -32), True)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment