Re: Proposed new package

From: Date: Tue, 18 Feb 2003 08:53:21 +0000
Subject: Re: Proposed new package
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-13439@lists.php.net to get a copy of this message
Hi, Tim Thorpe wrote:
The finished abstraction class will be able automatically incorporate and use whatever algorithms are provided as modules. As I have it now, this would be the usage for DES (and other symmetric ciphers): $des = Crypt::init('DES'); $data = 'my data'; $key = 'my key'; $mode = 'ecb'; $cipherText = $des->encrypt($data, $key, $mode); $clearText = $des->decrypt($cipherText, $key, $mode); Usage for RSA (and other asymmetric ciphers): $rsa = Crypt::init('RSA'); $data = 'my data'; $keyPublic = 'Public RSA key'; $keyPrivate = 'Private RSA key'; $cipherText = $rsa->encrypt($data, $keyPrivate); $clearText = $rsa->decrypt($cipherText, $keyPublic); Usage for MD5 (and other digest/hash algorithms) $md5 = Crypt::init('md5'); $data = 'my data'; $hash = $md5->encrypt($data); This abstraction class cleanly unifies the interfaces of the various encryption schemes out there today. It also implements class overrides in a way that allows true modularity. Say for example the module DES implements not only the minimum encryption and decryption methods, but also implements a method that generates key parity (which it does). Say also that the system the module is running on has mcrypt loaded. The abstraction class would make the mcrypt module a child of the DES module, overriding the encrypt and decrypt methods with the much faster mcrypt wrappers, while leaving addon methods like parity() intact. Example: $des = Crypt::init('DES'); $data = 'my data'; $key = $des->parity('my key'); // This call is handled by the Crypt_DES module $mode = 'ecb';
$cipherText = $des->encrypt($data, $key, $mode);      // These calls are
handled by the Crypt_Mcrypt module $clearText = $des->decrypt($cipherText, $key, $mode); // These calls are handled by the Crypt_Mcrypt module How does this strike you?
sounds good. do you already have sourcecode for reviewing? Personaly, I would propose to name the method for Digest-algorithms not encrypt, I would propose to name something like hash() or makeHash() or something similar. Because you can also use DES for generating Hashes. bye, -- ------------------------------- ------------------------------------- Michael Bretterklieber - Michael.Bretterklieber@jawa.at JAWA Management Software GmbH - http://www.jawa.at Liebenauer Hauptstr. 200 -------------- privat --------------- A-8041 GRAZ GSM: ++43-(0)676-93 96 698 Tel: ++43-(0)316-403274-12 E-mail: michael@bretterklieber.com Fax: ++43-(0)316-403274-10 http://www.bretterklieber.com ------------------------------- ------------------------------------- "...the number of UNIX installations has grown to 10, with more expected..." - Dennis Ritchie and Ken Thompson, June 1972

« previous php.pear.dev (#13439) next »