I've become overwhelmed in terms of 2 way encryption. There's lots of info but I can't seem to find a solid one to suit my needs.
I have the following in PHP:
function encrypt( $key, $string ){ $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $string, MCRYPT_MODE_CBC, md5(md5($key)))); return $encrypted; } function decrypt( $key, $encrypted ){ $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($encrypted), MCRYPT_MODE_CBC, md5(md5($key))), "\0"); return $decrypted; } //Stripped out code for readability $encryption_Key = 'password'; //such strong, many vulnerable $name = encrypt($encryption_Key, $_POST['name']); $stmt = $conn->prepare("UPDATE Customers SET name = ? WHERE blah = ?"); $stmt->bind_param('si', $name, $blah); $stmt->execute(); $stmt->close(); but looking at mySQL, i get jargon like:
~/�Jꎈ*3��9k��Z�f������ï and unreadable characters when I decrypt like so:
$name = decrypt($encryption_Key, $name ); The field type for the name column is currently:
varchar(200) I have seen examples where they you use binary or blob as the field type but I'm not having much luck. Some help in the right direction would be greatly appreciated.