begin process at 2012 05 27 22:09:36
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Class et Objet ( POO )

 > CLASS MCRYPT

CLASS MCRYPT


 Information sur la source

 Description

gestion de la class mcrypt, c'est la version préalphabêta si vous voyez :)
je la poste pour voir les améliorations que d'autres pourront apporter.

Source

  • <?php
  • class mcrypt {
  • var $algorithm = MCRYPT_TRIPLEDES;
  • var $mode = MCRYPT_MODE_CFB;
  • var $defKey ='54087c0be6244cb2755efa439469302d';
  • var $key;
  • function mcrypt($arg = NULL)
  • {
  • if($arg == NULL)
  • {
  • $this->key = $this -> defKey;
  • } else {
  • $this->key = $arg;
  • }
  • $this->openModule();
  • }
  • function openModule()
  • {
  • if($this->td = @mcrypt_module_open($this ->algorithm,'',$this ->mode,''))
  • {
  • $this -> createIv();
  • } else {
  • trigger_error('Open module failt',E_USER_ERROR);
  • }//end if
  • }
  • function createIv()
  • {
  • if($this -> size = @mcrypt_get_iv_size ($this ->algorithm, $this->mode))
  • {
  • if($this -> iv = @mcrypt_create_iv($this->size,MCRYPT_RAND))
  • {
  • mcrypt_generic_init ($this -> td, substr($this->key,0,mcrypt_enc_get_key_size($this -> td)), $this -> iv);
  • } else {
  • trigger_error('mcrypt_create_iv failt',E_USER_ERROR);
  • }//end if
  • } else {
  • trigger_error('mcrypt_get_iv_size failt',E_USER_ERROR);
  • }//end if
  • }//end function
  • function encrypt($string)
  • {
  • return mcrypt_generic ($this -> td, $string);
  • }
  • function decrypt($string)
  • {
  • return mdecrypt_generic($this -> td,$string);
  • }
  • function closeMcrypt()
  • {
  • mcrypt_generic_deinit ($this->td);
  • mcrypt_module_close ($this->td);
  • }
  • }
  • ?>
<?php

class mcrypt {
var $algorithm = MCRYPT_TRIPLEDES;
var $mode = MCRYPT_MODE_CFB;
var $defKey ='54087c0be6244cb2755efa439469302d';
var $key;

	function mcrypt($arg = NULL)
	{
	
		if($arg == NULL)
		{
		
			$this->key = $this -> defKey;
		
		}	else {
			
			$this->key = $arg;
		}

		$this->openModule();
	
	}
	
	function openModule()
	{

		if($this->td = @mcrypt_module_open($this ->algorithm,'',$this ->mode,''))
		{
		
			$this -> createIv();
		
		}	else {
		
			trigger_error('Open module failt',E_USER_ERROR);
			
		}//end if
	
	}
	
	
	function createIv()
	{
	
		if($this -> size = @mcrypt_get_iv_size ($this ->algorithm, $this->mode))
		{
			
			if($this -> iv = @mcrypt_create_iv($this->size,MCRYPT_RAND))
			{
			
					mcrypt_generic_init ($this -> td, substr($this->key,0,mcrypt_enc_get_key_size($this -> td)), $this -> iv);

				
			} else {

				trigger_error('mcrypt_create_iv failt',E_USER_ERROR);
				
			}//end if
		
		} else {
		
			trigger_error('mcrypt_get_iv_size failt',E_USER_ERROR);
		
		}//end if
	
	}//end function
	
	function encrypt($string)
	{
	
		return mcrypt_generic ($this -> td, $string);
		
	}
	
	function decrypt($string)
	{
	
		return mdecrypt_generic($this -> td,$string);
	
	}
	
	function closeMcrypt()
	{
	
	    mcrypt_generic_deinit ($this->td);
		mcrypt_module_close ($this->td);

	
	}

}
?>

 Conclusion

alors, pour l'utiliser:

<?
require_once('crypt.php') //dépendra du nom de votre fichier

$mcryp = new mcrypt(); //vous pouvez définir votre prore password new mcrypt('VotrePass');

$mcrypt->encrypt('Votre texte secret');

$mcrypt->decrypt('Votre texte crypter');//doit être décrypter avec le pass d'encryption :)


$mcrypt->closeMcrypt(); //ferme le module;


//----------- divers ------------------

$mcrypt->listAlgo(); //voir les algorithm installés chez votre provider;
$mcrypt->listMode();//idem mais pour les différents mode

?>

voilà, reste plus qu'a l'améliorer et le redistribuer


 Sources du même auteur

VÉRIFIER SI TOUT LE FORMULAIRE EST COMPLÈTÉ

 Sources de la même categorie

Source avec Zip GÉNÉRATION AUTOMATIQUE DE FICHIER .CLASS.PHP EN FONCTION D'U... par ig3
CLASSE D'OBJET DE CRYPTAGE ET DÉCRYPTAGE DE CHAINES DE CARAC... par 8Tnerolf8
Source avec Zip MY.DEVIANTART API par inwebo
CLASSE DE GESTION DE "VARIABLES GLOBALES D'ENVIRONNEMENT" par pifou25
Source avec Zip COLLECTION.CLASS.MIN.PHP par thunderhunter

Commentaires et avis

Commentaire de matrey le 12/11/2003 21:04:16

???
je vois pas l'intérêt, les fonctions sont déjà toutes prêtes... non ?

Commentaire de ErAzEr le 12/11/2003 21:35:56

http://be2.php.net/manual/fr/function.mcrypt-module-open.php

l'interêt est d'apprendre tout simplement

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,562 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales