1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
<fieldset><legend><strong><u>Cryptage d'information avec clé* :</u></strong></legend>
<?php
if (isset ($_POST['formulaire_1_cle_cryptage']) && isset ($_POST['formulaire_1_information_a_crypter']))
{$cle_de_cryptage = $_POST['formulaire_1_cle_cryptage'];
$information_a_crypte = $_POST['formulaire_1_information_a_crypter'];
$algo = MCRYPT_BLOWFISH;
$mode = MCRYPT_MODE_NOFB;
// calcul des longueurs max de la clé et de l'IV
$key_size = mcrypt_module_get_algo_key_size($algo);
$iv_size = mcrypt_get_iv_size($algo, $mode);
// création d'un IV de la bonne longueur débutant par exemple de iv suivi de 0
$iv = mcrypt_create_iv($iv_size, substr("uaGx6mUahpxKLpD1DbvIReEGlBz3jEo",0,$iv_size));
// Mise à longueur suivant l'algorithme et le mode associé
$cle_de_cryptage = substr($cle_de_cryptage, 0, $key_size);
// Créptage
$information_crypte = mcrypt_encrypt($algo, $cle_de_cryptage, $information_a_crypte, $mode, $iv);
// Décryptage
$information_decrypte = mcrypt_decrypt($algo, $cle_de_cryptage, $information_crypte, $mode, $iv);
echo ('Informations à cryptés = "'.$information_a_crypte.'"<br> Informations cryptés = "'.$information_crypte.'"<br> Information décrypté = "'.$information_decrypte.'"');
unset ($_POST['formulaire_2_cle_cryptage'], $_POST['formulaire_2_information_a_crypter']);
;}
else {
?>
<form method="post">
<ul>
<li><strong><u>Clé de cryptage :</u></strong></li>
<input name="formulaire_1_cle_cryptage" type="text" size="100" maxlength="256">
</ul>
<ul>
<li><strong><u>Information à crypté :</u></strong>
</li>
<textarea name="formulaire_1_information_a_crypter" cols="100" rows="10" wrap="physical"></textarea>
</ul>
<input type="submit" value="Crypter"> <input name="" type="reset">
</form>
<?php
}
?>
(* = Décryptage possible)
</fieldset> |
Partager