Jump to content

AES encrpytion


prime

Recommended Posts

Hi trying to encrypt a little chat box thing I have as some of the stuff being discussed is somewhat confidential, I'm trying to store this in the database in aes encryption, not sure exactly whats going wrong, but all the data appears to be going in blank.

 

the program works fine without aes, so I know the rest of the program is good, just not the encrypting and decrypting bit

 

insert code

<?php
include('sessioncall.inc');
?><html><head></head><body bgcolor="darkblue">

<?php
$chat_submitted = $_POST['chatenter'];

	if($chat_submitted == "TRUE")
		{
			$chat = $_POST['chat'];


$host="*****";
$user="*****";
$password="*****";
$database="*****";
$connection = mysql_connect($host,$user,$password)
	or die("couldn't connect toserver");
$db = mysql_select_db($database,$connection)
	or die("couldn't select database");



$query = "INSERT INTO ***** (primename, comments) VALUES ('$name', (AES_ENCRYPT('$chat', '*****' )))";


$result = mysql_query($query)
	or die("couldn't execute query");




		}

?>


<form action="<?php echo "$this_file"; ?>" method="post">
<input type="hidden" name="chatenter" value="TRUE">
<center><input name="chat" type="text" size="35"></center>
</form>



</body></html>

 

reader code

<?php
include('sessioncall.inc');

$display = 10;
?>

<?php
$chat_username = ucfirst(strtolower($_SESSION['username']));
?>
<html><head >

<META HTTP-EQUIV="refresh" content="8;URL=<?php echo "$this_file"; ?>"> 


</head><body bgcolor="black"><font color="white">

<?php
$host="*****";
$user="*****";
$password="*****";
$database="*****";
$connection = mysql_connect($host,$user,$password)
	or die("couldn't connect toserver");
$db = mysql_select_db($database,$connection)
	or die("couldn't select database");




$query = "Select user_id, primename, (AES_DECRYPT('comments','*****'))  from ***** order by user_id DESC LIMIT $display";

$result = mysql_query($query)
	or die("couldn't execute query");

while ($row = mysql_fetch_array($result))



    {
        extract($row);

echo "<b>$primename</b>: $comments<br />";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/89117-aes-encrpytion/
Share on other sites

Try...

 

<?php

$query = "SELECT user_id, primename, (AES_DECRYPT('comments','*****')) AS comment FROM ***** ORDER BY user_id DESC LIMIT $display";
$result = mysql_query($query) or die("couldn't execute query");
while ($row = mysql_fetch_array($result)) {
  extract($row);
  echo "<b>$primename</b>: $comment<br />";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/89117-aes-encrpytion/#findComment-456497
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.