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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.