/**
- * Php des encryption and decryption
- * By http://bbs.it-home.org
- */
- Function do_mencrypt ($ input, $ key)
- {
- $ Input = str_replace ("" n "," ", $ input );
- $ Input = str_replace ("" t "," ", $ input );
- $ Input = str_replace ("" r "," ", $ input );
- $ Key = substr (md5 ($ key), 0, 24 );
- $ Td = mcrypt_module_open ('tripledes ', '', 'ECB ','');
- $ Iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($ td), MCRYPT_RAND );
- Mcrypt_generic_init ($ td, $ key, $ iv );
- $ Encrypted_data = mcrypt_generic ($ td, $ input );
- Mcrypt_generic_deinit ($ td );
- Mcrypt_module_close ($ td );
- Return trim (chop (base64_encode ($ encrypted_data )));
- }
// $ Input-stuff to decrypt
- // $ Key-the secret key to use
- Function do_mdecrypt ($ input, $ key)
- {
- $ Input = str_replace ("" n "," ", $ input );
- $ Input = str_replace ("" t "," ", $ input );
- $ Input = str_replace ("" r "," ", $ input );
- $ Input = trim (chop (base64_decode ($ input )));
- $ Td = mcrypt_module_open ('tripledes ', '', 'ECB ','');
- $ Key = substr (md5 ($ key), 0, 24 );
- $ Iv = mcrypt_create_iv (mcrypt_enc_get_iv_size ($ td), MCRYPT_RAND );
- Mcrypt_generic_init ($ td, $ key, $ iv );
- $ Decrypted_data = mdecrypt_generic ($ td, $ input );
- Mcrypt_generic_deinit ($ td );
- Mcrypt_module_close ($ td );
- Return trim (chop ($ decrypted_data ));
- }
- ?>
Articles you may be interested in: Implementation methods of des encryption and decryption (php net) php code encrypted with 3des (compatible with. net) |