Re: [PHP] mcrypt and PHP to encrypt values to be passed to differend server

This is a discussion on Re: [PHP] mcrypt and PHP to encrypt values to be passed to differend server within the PHP General forums, part of the PHP Programming Forums category; Hi, Monday, December 29, 2003, 9:30:11 AM, you wrote: MW> Hello! MW> I'm trying to ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-29-2003
Tom Rogers
 
Posts: n/a
Default Re: [PHP] mcrypt and PHP to encrypt values to be passed to differend server

Hi,

Monday, December 29, 2003, 9:30:11 AM, you wrote:
MW> Hello!

MW> I'm trying to use mcrypt to encrypt some values (login and password) I have
MW> to pass from one website to another.


You will need to pass the $iv which kinda defeats the object of it, or
use a null one. Here is a class I use for this which also corrects the
string lengths as decryption will usually have a few /0 tacked on to
make it a block size:

class encrypt_class{
var $secret;
function encrypt_class(){
$this->secret = 'choose your own pass phrase here';
}
Function encode($id){
$eid = $iv = 0;
$len = strlen($id);
$id = $len.'-'.$id;
$td = mcrypt_module_open(MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, "");
$key = substr($this->secret, 0, mcrypt_enc_get_key_size ($td));
$iv = pack("a".mcrypt_enc_get_iv_size($td),$iv);
mcrypt_generic_init ($td, $key, $iv);
$eid = base64_encode(mcrypt_generic ($td, $id));
mcrypt_generic_deinit($td);
return $eid;
}
Function decode($eid){
$id = $iv = 0;
$td = mcrypt_module_open (MCRYPT_TripleDES, "", MCRYPT_MODE_ECB, "");
$key = substr($this->secret, 0, mcrypt_enc_get_key_size ($td));
$iv = pack("a".mcrypt_enc_get_iv_size($td),$iv);
mcrypt_generic_init ($td, $key, $iv);
$id = mdecrypt_generic ($td, base64_decode($eid));
$len = strtok($id,'-');
$id = substr($id,(strlen($len)+1),$len);
mcrypt_generic_deinit($td);
return $id;
}
}
//usage
$password = 'password';
$name = 'me';

$mesage[0] = $password;
$message[1] = $name;

$serial = serialize($message);

$enc = new encrypt_class();
$enc_message = $enc->encode($serial);
//send message ....?enc_message=$enc_message

//next page
$enc = new encrypt_class();
$serial = $enc->decode($_GET['enc_message']);
$message = unserialize($serial);
print_r($message);

--
regards,
Tom
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:22 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0