Add an encryption system
This commit is contained in:
parent
93ea6f4151
commit
dc91e89393
@ -19,6 +19,30 @@ foreach ($_GET as $k => $t)
|
|||||||
{
|
{
|
||||||
$paste = new Paste($kout[1]);
|
$paste = new Paste($kout[1]);
|
||||||
|
|
||||||
|
if (!empty($paste->crypt) && empty($_POST["passwd"]))
|
||||||
|
{
|
||||||
|
?>
|
||||||
|
<div id="corps" style="text-align: center;">
|
||||||
|
<h1>
|
||||||
|
<?php echo htmlentities($paste->title); ?>
|
||||||
|
</h1>
|
||||||
|
<h2><?php echo $paste->get_subtitle(); ?></h2>
|
||||||
|
<div>
|
||||||
|
<form method="post" action="?<?php echo $kout[1]; ?>">
|
||||||
|
<fieldset class="paste_form">
|
||||||
|
<label for="title">Mot de passe :</label>
|
||||||
|
<input type="password" size="42" id="passwd" name="passwd">
|
||||||
|
<br><br>
|
||||||
|
<input type="submit" value="Voir le texte">
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!empty($paste->crypt))
|
||||||
|
$paste->crypt($_POST["passwd"]);
|
||||||
|
|
||||||
if (!empty($kout[3]) && is_file(Paste::get_path($kout[3])))
|
if (!empty($kout[3]) && is_file(Paste::get_path($kout[3])))
|
||||||
$diff = new Paste($kout[3]);
|
$diff = new Paste($kout[3]);
|
||||||
?>
|
?>
|
||||||
@ -38,6 +62,7 @@ foreach ($_GET as $k => $t)
|
|||||||
else
|
else
|
||||||
echo $paste->get_code();
|
echo $paste->get_code();
|
||||||
echo $paste->show_answers();
|
echo $paste->show_answers();
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -67,9 +92,11 @@ else
|
|||||||
<form method="post" action="save.php">
|
<form method="post" action="save.php">
|
||||||
<fieldset class="paste_form">
|
<fieldset class="paste_form">
|
||||||
<label for="title">Titre :</label>
|
<label for="title">Titre :</label>
|
||||||
<input type="text" size="50" id="title" name="title" value="<?php
|
<input type="text" size="42" id="title" name="title" value="<?php
|
||||||
echo $paste->title;
|
echo $paste->title;
|
||||||
?>">
|
?>">
|
||||||
|
<label for="author">Auteur :</label>
|
||||||
|
<input type="text" maxlength="64" size="25" id="author" name="author">
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
<label for="content">Contenu :</label><br>
|
<label for="content">Contenu :</label><br>
|
||||||
@ -77,8 +104,8 @@ else
|
|||||||
echo htmlentities(utf8_decode($paste->content));
|
echo htmlentities(utf8_decode($paste->content));
|
||||||
?></textarea><br><br>
|
?></textarea><br><br>
|
||||||
|
|
||||||
<label for="author">Auteur :</label>
|
<label for="crypt" style="font-style: italic;">Mot de passe :</label>
|
||||||
<input type="text" maxlength="64" size="35" id="author" name="author">
|
<input type="text" maxlength="64" size="25" id="crypt" name="crypt">
|
||||||
|
|
||||||
<label for="lang">Langage :</label>
|
<label for="lang">Langage :</label>
|
||||||
<select id="lang" name="lang">
|
<select id="lang" name="lang">
|
||||||
|
@ -14,6 +14,7 @@ class Paste
|
|||||||
var $ip;
|
var $ip;
|
||||||
var $ref = NULL;
|
var $ref = NULL;
|
||||||
var $hash;
|
var $hash;
|
||||||
|
var $crypt = NULL;
|
||||||
var $answers = array();
|
var $answers = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -30,6 +31,29 @@ class Paste
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function cxor($msg, $cle)
|
||||||
|
{
|
||||||
|
$cle = hash("whirlpool", $cle);
|
||||||
|
|
||||||
|
$xor = NULL;
|
||||||
|
for($i = 0; $i < strlen($msg); $i++)
|
||||||
|
$xor .= substr($msg,$i,1) ^ substr($cle, $i % strlen($cle), 1);
|
||||||
|
return $xor;
|
||||||
|
}
|
||||||
|
|
||||||
|
function crypt($key)
|
||||||
|
{
|
||||||
|
if (!empty($this->crypt))
|
||||||
|
$this->crypt = Paste::cxor($this->crypt, $key);
|
||||||
|
else
|
||||||
|
$this->crypt = Paste::cxor(sha1($key), $key);
|
||||||
|
|
||||||
|
if ($this->crypt == sha1($key))
|
||||||
|
$this->content = Paste::cxor(base64_decode($this->content), $key);
|
||||||
|
else
|
||||||
|
$this->content = base64_encode(Paste::cxor($this->content, $key));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load or reload the file and set attributes
|
* Load or reload the file and set attributes
|
||||||
*/
|
*/
|
||||||
@ -58,6 +82,11 @@ class Paste
|
|||||||
else
|
else
|
||||||
$this->hash = NULL;
|
$this->hash = NULL;
|
||||||
|
|
||||||
|
if ($doc->getElementsByTagName("crypt")->length > 0)
|
||||||
|
$this->crypt = base64_decode($doc->getElementsByTagName("crypt")->item(0)->textContent);
|
||||||
|
else
|
||||||
|
$this->crypt = NULL;
|
||||||
|
|
||||||
for ($i = 0; $i < $doc->getElementsByTagName("answer")->length; $i++)
|
for ($i = 0; $i < $doc->getElementsByTagName("answer")->length; $i++)
|
||||||
$this->answers[] = $doc->getElementsByTagName("answer")->item($i)->textContent;
|
$this->answers[] = $doc->getElementsByTagName("answer")->item($i)->textContent;
|
||||||
|
|
||||||
@ -130,6 +159,9 @@ class Paste
|
|||||||
$xml_paste->appendChild(
|
$xml_paste->appendChild(
|
||||||
$xml->createElement("content", $this->content));
|
$xml->createElement("content", $this->content));
|
||||||
|
|
||||||
|
if (!empty($this->crypt))
|
||||||
|
$xml_paste->appendChild(
|
||||||
|
$xml->createElement("crypt", base64_encode($this->crypt)));
|
||||||
if (!empty($this->ref))
|
if (!empty($this->ref))
|
||||||
{
|
{
|
||||||
//Also indicate in the parent file
|
//Also indicate in the parent file
|
||||||
@ -179,6 +211,9 @@ class Paste
|
|||||||
|
|
||||||
//TODO: allow uploading file
|
//TODO: allow uploading file
|
||||||
$this->content = $dict["content"];
|
$this->content = $dict["content"];
|
||||||
|
|
||||||
|
if (!empty($dict["crypt"]))
|
||||||
|
$this->crypt($dict["crypt"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user