Object of class .. could not be converted to string
<p>I made my first class and I'm having trouble converting the objects back into strings.</p>

<pre><code>class Cryption
{
    var $data;
    var $salt;

function __construct($data, $salt)
{
    $this-&gt;data = $data;
    $this-&gt;salt = $salt;
}

function sha512()
{
    $sodium = 'Na';
    return hash_hmac("sha512", $this-&gt;data . $this-&gt;salt, $sodium);
}

function encrypt()
{
    $salt = substr(sha512(($this-&gt;key), 'brownies'), 0, 30);
    return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $salt, $this-&gt;data, MCRYPT_MODE_CBC, md5($salt)));
}
</code></pre>

<p>When I use it:</p>

<pre><code>$password = new Cryption(mysql_real_escape_string(trim($_POST['password'])), 'pepper');
$password-&gt;sha512();
</code></pre>

<p>It says 'PHP Catchable fatal error:  Object of class Cryption could not be converted to string'</p>

<p>I don't really know how to get it back into a string.  May someone please help me?</p>

<p>Thank you.</p>

<p>Edit: </p>

<pre><code>&lt;?php
require("config.php");
include("includes/cryption/cryption.php");

$username = mysql_real_escape_string(trim($_POST['username']));
$password = new Cryption(mysql_real_escape_string(trim($_POST['password'])), 'pepper'); //use a different salt next time such as a special salt for each user
$password-&gt;sha512();

$result = mysql_query("SELECT * FROM `administrators` WHERE username='$username' and password='$password'");
$row = mysql_fetch_row($result);
$count = mysql_num_rows($result);

if ($count == 1) {
    if (isset($_POST['remember'])) {
        session_start();
        $_SESSION['user'] = array(
            'id' =&gt; $row[0],
            'username' =&gt; $row[1],
            'password' =&gt; $row[2]
        );
        $userid = new Cryption($_SESSION['user']['id'], 'kkfishing');
        $session = new Cryption($_SESSION['user']['username'], 'kkfishing');
        $validated = new Cryption($_SESSION['user']['password'], 'kkfishing');

        setcookie("uniqueid", $userid-&gt;encrypt(), time() + 60 * 60 * 24 * 100, "/"); //100 days
        setcookie("kksessionid", $session-&gt;encrypt(), time() + 60 * 60 * 24 * 100, "/");
        setcookie("kkuserid", $validated-&gt;encrypt(), time() + 60 * 60 * 24 * 100, "/");//disguised cookie name
    }
    session_start();
    $_SESSION['authenticated'] = $row[0];
    echo '1'; //true
    exit;
}
else
{
    echo '0'; //false
    exit;
}
?&gt;
</code></pre>
