Exemple #1
0
/***********************************************************/
/* Declare a new instance of AES with the secret key       */
/***********************************************************/
$cipher = new AES("TEST");
//                  */
/***********************************************************/
/* To encrypt a message, call the Encrypt() function from  */
/* the instance with the desired message as the parameter. */
/***********************************************************/
$encrypted = $cipher->Encrypt("Worked!");
//                  */
/***********************************************************/
/* To decrypt a message, call the Decrypt() function from  */
/* the instance with the desired message as the parameter. */
/***********************************************************/
$decrypted = $cipher->Decrypt($encrypted);
echo "Key:       " . $cipher->key . "\n";
echo "Encrypted: " . $encrypted . "\n";
echo "Decrypted: " . $decrypted . "\n\n";
echo "The whole source can be found on https://github.com/halitalf/cross-aes\n";
class AES
{
    var $key = "";
    function __construct($SecretKey)
    {
        $this->key = $this->Pass2Key($SecretKey);
    }
    function Pass2Key($SecretKey)
    {
        return substr(base64_encode(pack('H*', hash("sha512", $SecretKey))), 0, 32);
    }