OpenSSL_Decrypt returning blank data

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
lukekfrost
New php-forum User
New php-forum User
Posts: 1
Joined: Tue Aug 14, 2018 3:07 am

Tue Aug 14, 2018 4:06 am

Good Morning All,

I am trying to develop a basic website that will take data from a database and decrypt it before displaying it. The data is stored into a database using a vb.net application and is encrypted prior to saving based on the following github post https://gist.github.com/odan/138dbd41a0 ... b03d814d7c.

I have the following php code in the decrypt area

Code: Select all

<?php

			$servername = "server";
			$username = "user";
			$password = "password";
			$dbname = "database";
				
			$sqlcon = mysqli_connect($servername, $username, $password, $dbname);
		
			// Check connection
			if (mysqli_connect_error()) {
			    die("Database connection failed: " . mysqli_connect_error());
			}

			$sql = "SELECT * FROM tblcustomersinfo";
			$result = $sqlcon->query($sql);

			if ($result->num_rows > 0) {
				echo "<div style='overflow-x:auto;'><table style='width:100%' min-width='60px'>
			<col width=10px>
			<col width=22.5%>
			<col width=22.5%>
			<col width=22.5%>
			<col width=22.5%>
		  <tr>
			<th>View</th>
			<th>Title</th> 
			<th>First Name</th>
			<th>Surname</th>
			  <th>Postcode</th>
		  </tr>";
				// output data of each row
				while($row = $result->fetch_assoc()) {		
					$encryptionpassword = '11DiGiTs123';
					$method = 'aes-256-cbc';
					$hashedpassword = password_hash($encryptionpassword, PASSWORD_BCRYPT, ['cost' => 12]);

					$iv = chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0) . chr(0x0);
					
					$title = openssl_decrypt(base64_decode($row["title"]), $method, $hashedpassword, OPENSSL_RAW_DATA, $iv);
					$first_name = openssl_decrypt(base64_decode($row["first_name"]), $method, $hashedpassword, OPENSSL_RAW_DATA, $iv);
					$surname = openssl_decrypt(base64_decode($row["surname"]), $method, $hashedpassword, OPENSSL_RAW_DATA, $iv);
					$postcode = openssl_decrypt(base64_decode($row["postcode"]), $method, $hashedpassword, OPENSSL_RAW_DATA, $iv);
						echo "<tr>
			<td align='center'><a href='customerdetails.php?ID=".$row["urn"]."'>".$row["urn"]."</a></td>
			<td align='center'>" .$title. "</td> 
			<td align='center'>" .$first_name. "</td>
			  <td align='center'>" .$surname. "</td>
			  <td align='center'>" .$postcode. "</td>
					</tr>";
												 
					}
				echo "</table></br></div>";
			} else {
				echo "No Customers";
			}
			$sqlcon->close();
	
		?>
However the webpage that is being displayed no data being displayed in the associated cells. Saying this however if you just display the raw database data then the encrypted data is displayed.

I'm new to php and web development so some assistance would be great as from looking over the code everything seems ok and also from looking at the php documentation this seems to be correct aswell.

Thanks in advanced

Frosty

Post Reply