<?php
require_once("./Cipher.php");
$cipher = new Cipher(MCRYPT_BLOWFISH, MCRYPT_MODE_ECB);
$conn = mysql_connect("host", "user", "pass");
mysql_select_db("dbname", $conn);
$key = "a secret key.";
if ($_POST) {
$name = $cipher->encrypt($_POST['name'], $key);
$phone = $cipher->encrypt($_POST['phone']);
$iv = $cipher->getIV();
mysql_query("INSERT INTO `phones` (`id`, `name`, `phone`, `iv`) VALUES (NULL, '".$name."', '".$phone."', '".$iv."')", $conn);
/*
CREATE TABLE `phones` (
`id` int(10) unsigned NOT NULL auto_increment,
`name` varchar(64) NOT NULL,
`phone` varchar(64) NOT NULL,
`iv` varchar(64) NOT NULL,
PRIMARY KEY(`id`)
);
*/
}
?>
<html>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
name: <input type="text" name="name" value="" />
<br />
phone: <input type="text" name="phone" value="" />
<br />
<input type="submit" value="Add Number" />
</form>
<hr />
<pre>
<?php
echo "\r\n";
$result = mysql_query("SELECT * FROM `phones` ORDER BY `name` ASC");
while ($row = mysql_fetch_object($result)) {
$name = $cipher->decrypt($row->name, $key, $row->iv);
$phone = $cipher->decrypt($row->phone);
echo $name.":\n";
echo $phone."\n\n";
}
echo "\r\n";
?>
</pre>
</body>
</html>
|