Note that there are some explanatory texts on larger screens.

plurals
  1. PODecrypting certain fields from a mysql database using PHP
    primarykey
    data
    text
    <p>I have this PHP script </p> <pre><code> &lt;?php //assume this is the key, declared as variable $cipherKey in the file cipherkey.php. include ('cipherkey.php') class Cipher { private $passKey; private $iv; function __construct( $inputKey ) { $this-&gt;passKey = hash( 'sha256', $inputKey, true ); $this-&gt;iv = mcrypt_create_iv( 32 ); } function encryptThis( $inputText ) { $cipher = mcrypt_encrypt( MCRYPT_RIJNDAEL_256, $this-&gt;passKey,$inputText, MCRYPT_MODE_ECB, $this-&gt;iv ); $encrypted = base64_encode( $cipher ); return $encrypted; } function decryptThis( $inputText ) { $decipher = mcrypt_decrypt( MCRYPT_RIJNDAEL_256, $this-&gt;passKey, base64_decode( $inputText ), MCRYPT_MODE_ECB, $this-&gt;iv ); $decrypted = trim( $decipher ); return $decrypted; } } ?&gt; </code></pre> <p>This script is used to encrypt certain fields in a mysql database like this;</p> <pre><code>if( isset( $prescRequester, $patientName, $patientDOB, $contactPhone, $medType1, medType1_dose, $medType1_freq, $pharmacyName, $pharmacyPhone ) ) { $prep = $db-&gt;prepare( "INSERT INTO renal_prescRequest( date, prescRequester, patientRelationship, patientName, patientDOB, contactPhone, contactEmail, physician, medProvider, medType1, medType1_dose, medType1_freq, medType2, medType2_dose, medType2_freq, medType3, medType3_dose, medType3_freq, ninetyDaySupply, pharmacyName, pharmacyPhone, comments ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) "); $prep-&gt;bind_param( 'ssssssssssssssssssssss', $date, $cipher-&gt;encryptThis( $prescRequester ), $cipher-&gt;encryptThis( $patientRelationship ), $cipher-&gt;encryptThis( $patientName ), $cipher-&gt;encryptThis( $patientDOB ), $cipher-&gt;encryptThis( $contactPhone ), $cipher-&gt;encryptThis( $contactEmail ), $physician, $medProvider, $cipher-&gt;encryptThis( $medType1 ), $medType1_dose, $medType1_freq, $cipher-&gt;encryptThis( $medType2 ), $medType2_dose, $medType2_freq, $cipher-&gt;encryptThis( $medType3 ), $medType3_dose, $medType3_freq, $ninetyDaySupply, $pharmacyName, $pharmacyPhone, $comments ); $prep-&gt;execute(); $prep-&gt;close(); $db-&gt;close(); </code></pre> <p>I am not this author of this code. But I am supposed to decrypt the encrypted fields. So I did something like this ;</p> <pre><code> $cipher = new Cipher ( $cipherKey ); $id = $_GET['id']; $query = "SELECT * FROM renal_clinicalTrial WHERE id = '".$id."'"; $result = mysql_query($query); if(!$result){ die("Unable to perform query". mysql_error()); } while($row = mysql_fetch_array($result)){ $firstname = $row[firstName]; $lastname = $row[lastName]; $address = $row[address]; $city = $row[city]; $state = $row[state]; $zipcode = $row[zipcode]; $email = $row[contactEmail]; $phone = $row[contactPhone]; $cipher-&gt;decryptThis($firstname); $cipher-&gt;decryptThis($lastname); $cipher-&gt;decryptThis($address); $cipher-&gt;decryptThis($city); $cipher-&gt;decryptThis($state); $cipher-&gt;decryptThis($zipcode); $cipher-&gt;decryptThis($email); $cipher-&gt;decryptThis($phone); </code></pre> <p>When i display the fields to the browser, I get the encrypted data instead of the decrypted data. Is there something I am overlooking here. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload