Re: CRYPT_BLOWFISH with PostgreSQL
| From: | Graham Clarke | Date: | Mon, 18 Jul 2005 03:24:03 +0000 |
| Subject: | Re: CRYPT_BLOWFISH with PostgreSQL | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-20031@lists.php.net to get a copy of this message | ||
Matthew - Thanks. Think I have this figured out using pack() & unpack().
The process goes as follows:
// encrypt data
$encVal = $b->encrypt($myValue);
// unpack data - convert from binary to hex
$dbVal = unpack("H*", $encVal);
insert $dbVal into database
the unpacked value now looks something like 4f4fe3bc3bb1b6dd6c143a396355ea24f471383c077d77f8daed1a540bb3ce22 rather then the regular encrypted value OO�;���l:9cU�$�q8<}w���ZT��"
Retrieve data from db
// pack - convert from hex to bin
$encVal = pack("H*", $dbVal);
// decrypt
$myValue = $b->decrypt($encVal);
// use strip_tags($myValue) if your decrypted value has a bunch of trialing squares.
Here is a reference for a Perl script using Blowfish --
http://linuxgazette.net/issue59/nielsen.html
Cheers
Graham
Matthew Fonda wrote:
Graham Clarke wrote:-- Graham Clarke grahamc@53tech.com www.53tech.com 603.643.9955Hi - We're tryig to use Crypt_Blowfish to encrypt data stored in a postgres db. This mostly works, however there are certain strings that do not decrypt properly - after decryption part of the sting looks as if it's still decryprted. For example - the string "44-56565656" decrypts to "44-56565�����UX" Following is an example of what we're doing: $encString = mysql_escape_string(encrypt(trim($myValue))); $decString = decrypt($myValueFromPG); the key is a simple text string Any insgihts are appreciated. Thanks GrahamHello, You must be careful of the order you call the functions. If you escape the encrypted string, it potentially will not be the same as the original. If you would like to give me an actually code I can look into fixing it. Regards, --Matthew