Hi,
I've read up all I could find on using the Pear Blowfish class, but am hitting a conceptual wall.
I have no trouble creating an instance of the class, setting a "key", encrypting some plain text, and decrypting the text FROM WITHIN THE SAME CLASS INSTANCE.
But, I plan to store the bin2hex of the encrypted text in a database, then later decrypt using the correct key. But when testing the following -- using one instance to encrypt and another instance to decrypt -- I can't seem to get my plaintext back. Instead I just get an error object saying my key is not initialized.
<code>
<?php
require_once 'Crypt/Blowfish.php';
/ Create the Crypt_Blowfish object using a secret key /
$in = new Crypt_Blowfish('secret key');
/ Encrypt some plain text /
$encrypted = $in->encrypt('secret content to be inserted into database');
/ Decrypt the secret message using a different instance of the class /
$out = new Crypt_Blowfish('secret key');
$decrypted = $out->decrypt(bin2hex($encrypted));
/ Echo the results /
echo 'Decrypted: ' . $decrypted;
?>
</code>
Shouldn't this work? Or am I misunderstanding some vital concept of 2-way encryption?
Any help at all would be greatly appreciated.