bin2hex / hex2bin help
Posted: Wed Aug 25, 2004 11:07 am
I'm building a system which will allow me to encrypt and store data in a MySQL DB. The encrypting and decrypting parts I have no problems with, however in order to store the number in the DB I need to perform a bin2hex conversion.
I am using a hex2bin function that I found somewhere on PHP Builder, to convert the stored, encrypted number back to hex, however when I perform these functions I am only getting half of the number converted (the first 8 characters). I am posting the code, any guidance or help is greatly appreciated.
thanks
I am using a hex2bin function that I found somewhere on PHP Builder, to convert the stored, encrypted number back to hex, however when I perform these functions I am only getting half of the number converted (the first 8 characters). I am posting the code, any guidance or help is greatly appreciated.
Code: Select all
<?php
//convert hex string to binary string (used in decrypt_data)
function hex2bin($data) {
$len = strlen($data);
for($i=0;$i<$len;$i+=2) {
$newdata .= pack("C",hexdec(substr($data,$i,2)));
}
return $newdata;
}
?>thanks