IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Script de codage et décodage avec clé compatible UTF-8


Sujet :

Langage PHP

  1. #21
    Candidat au Club
    Homme Profil pro
    Inscrit en
    Août 2007
    Messages
    24
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Août 2007
    Messages : 24
    Points : 4
    Points
    4
    Par défaut
    Excuse j'avais oublier d'activer les message d'erreur!
    Donc je redonne tous le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    43
    44
    45
    46
    47
    48
    49
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Cyptage avec clé.</title>
    <style type="text/css">
    <!--
     
    -->
    </style>
    </head>
     
    <body>
    <fieldset>
    <legend><u><strong>Script de cryptage*</strong></u></legend>
    <?
    if   (isset ($_POST['cle_de_cryptage']) && isset ($_POST['information_a_crypter']))
         {$cle_de_cryptage = $_POST['cle_de_cryptage'];
    	  $information_a_crypte = $_POST['information_a_crypter'];
          $algo = MCRYPT_BLOWFISH;
          $mode = MCRYPT_MODE_NOFB;
          $key_size = mcrypt_module_get_algo_key_size($algo);
          $iv_size = mcrypt_get_iv_size($algo, $mode);
          $iv = mcrypt_create_iv($iv_size, substr("Exemple par",0,$iv_size));
          $cle_de_cryptage = substr($cle_de_cryptage, 0, $key_size);
    	  $information_crypte = mcrypt_encrypt($algo, $cle_de_cryptage, $information_a_crypte, $mode, $iv);
          $information_decrypte = mcrypt_decrypt($algo, $cle_de_cryptage, $information_crypte, $mode, $iv);
    	  echo ('Informations à crypter = "'.$information_a_crypte.'"<br> Informations crypter = "'.$information_crypte.'"<br> Information décrypter = "'.$information_decrypte.'"');
    	  unset ($_POST['cle_cryptage'], $_POST['information_a_crypter']);}
    else { 
    ?>
    <form method="post">
    <ul>
    <li><u>Clé de cryptage :</u></li>
    <input name="cle_de_cryptage" type="text" size="100" maxlength="100" />
    <li><u>Information à crypté :</u></li>
    <textarea name="information_a_crypter" cols="100" rows="10" wrap="physical"></textarea>
    </ul>
    <input type="submit" value="Crypter">
    <input name="" type="reset">
    </form>
    <?
    ;}
    ?>
    (* = "Décryptage possible avec la clé")
    </fieldset>
    </body>
    </html>
    Et voici les messages d'erreurs :
    Warning: mcrypt_create_iv() expects parameter 2 to be long, string given in /Users/guillardmarc44/Sites/codage d'information UTF-8.php on line 24

    Warning: mcrypt_encrypt() [function.mcrypt-encrypt]: The IV parameter must be as long as the blocksize in /Users/guillardmarc44/Sites/codage d'information UTF-8.php on line 26

    Warning: mcrypt_decrypt() [function.mcrypt-decrypt]: The IV parameter must be as long as the blocksize in /Users/guillardmarc44/Sites/codage d'information UTF-8.php on line 27
    Tu as la correction; je suis preneur.

  2. #22
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    J'ai du remonter le temps, on est revenu à hier, même problème sur mcrypt_create_iv() qu'on a deja corrigé hier.

  3. #23
    Candidat au Club
    Homme Profil pro
    Inscrit en
    Août 2007
    Messages
    24
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Août 2007
    Messages : 24
    Points : 4
    Points
    4
    Par défaut
    Désoler je suis perdu là!
    C'est-ce que tu peux afficher le script qui marche bien chez toi pour que l'on reprenne à zéro?

  4. #24
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Ton tout premier script fonctionnait déjà en dehors de l'erreur qu'on t'avait fait corriger.

  5. #25
    Candidat au Club
    Homme Profil pro
    Inscrit en
    Août 2007
    Messages
    24
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Août 2007
    Messages : 24
    Points : 4
    Points
    4
    Par défaut
    Redonne le script qui est bon car je l'ai tellement modifier que je suis perdu !

  6. #26
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Repars du premier script, affiche les erreurs, lit la doc.

  7. #27
    Candidat au Club
    Homme Profil pro
    Inscrit en
    Août 2007
    Messages
    24
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Août 2007
    Messages : 24
    Points : 4
    Points
    4
    Par défaut
    J'ai corriger les erreurs! Voici mon script corriger :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    $cle_de_cryptage = $_POST['formulaire_1_cle_cryptage'];
    	  $information_a_crypte = $_POST['formulaire_1_information_a_crypter'];
          // calcul des longueurs max de la clé et de l'IV
          $key_size = mcrypt_module_get_algo_key_size(MCRYPT_CAST_256);
          $iv_size = mcrypt_get_iv_size(MCRYPT_CAST_256, MCRYPT_MODE_CFB);
          // création d'un IV de la bonne longueur débutant par exemple de iv suivi de 0
          $iv = mcrypt_create_iv($iv_size, MCRYPT_DEV_RANDOM);
          // 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(MCRYPT_CAST_256, $cle_de_cryptage, $information_a_crypte, MCRYPT_MODE_CFB, $iv);
          // Décryptage
          $information_decrypte = mcrypt_decrypt(MCRYPT_CAST_256, $cle_de_cryptage, $information_crypte, MCRYPT_MODE_CFB, $iv);
    	  echo ('Informations à cryptés = "'.$information_a_crypte.'"<br> Informations cryptés = "'.$information_crypte.'"<br> Information décrypté = "'.$information_decrypte.'"');
    	  ;}
    Mais j'ai toujours le problème!

  8. #28
    Candidat au Club
    Homme Profil pro
    Inscrit en
    Août 2007
    Messages
    24
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Août 2007
    Messages : 24
    Points : 4
    Points
    4
    Par défaut
    tu as mit quoi pour "$iv = mcrypt_create_iv()"?

  9. #29
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Chez moi ça fonctionne, le texte est bien déchiffré que je sois en UTF8 ou en ANSI.

  10. #30
    Candidat au Club
    Homme Profil pro
    Inscrit en
    Août 2007
    Messages
    24
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Août 2007
    Messages : 24
    Points : 4
    Points
    4
    Par défaut
    Ok! Si ça vient pas du script ça peux venir de quoi?
    Sachant que je suis sous mac avec mamp (équivalant de wamp).

Discussions similaires

  1. [Java] Script pour formatter un textarea avec des icones
    Par odoobe dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 26/09/2006, 09h30
  2. [HTML] PDF avec CSS compatible.. ça existe?
    Par MicaelFelix dans le forum Outils
    Réponses: 2
    Dernier message: 25/08/2006, 10h10
  3. Un script qui fermerait une page avec chrono ?
    Par beegees dans le forum Général JavaScript
    Réponses: 19
    Dernier message: 31/03/2006, 10h01
  4. script envoi mail et fax avec CDO
    Par RobinNono dans le forum ASP
    Réponses: 1
    Dernier message: 03/10/2005, 15h36
  5. Script test de deux chaine avec if
    Par kacedda dans le forum Linux
    Réponses: 6
    Dernier message: 02/05/2003, 15h38

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo