Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 04-11-2005, 02:47 PM two-way encryption?
Extreme Talker

Posts: 219
Location: UK, East Anglia
Trades: 0
Can someone explain to me a way of doing two-way encryption with a custom key that is used to encrypt and decrypt something like a password?
timsquash5 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-12-2005, 03:39 AM
Tekime's Avatar
Experienced Talker

Posts: 46
Name: Gabriel Harper
Location: Maine
Trades: 0
Something along the lines of this, but don't expect this to be perfect.

PHP Code:
function key_encrypt($text$key)
{
    
$iv_size mcrypt_get_iv_size(MCRYPT_XTEAMCRYPT_MODE_ECB);
    
$iv mcrypt_create_iv($iv_sizeMCRYPT_RAND);
    
$enc mcrypt_encrypt(MCRYPT_XTEA$key$textMCRYPT_MODE_ECB$iv);
    return 
$enc;
}

function 
key_decrypt($enc$key)
{
    
$iv_size mcrypt_get_iv_size(MCRYPT_XTEAMCRYPT_MODE_ECB);
    
$iv mcrypt_create_iv($iv_sizeMCRYPT_RAND);
    
$crypttext mcrypt_decrypt(MCRYPT_XTEA$key$encMCRYPT_MODE_ECB$iv);
    return 
$crypttext;
}

// 16 char keystring
$key '9a8fy29hf97ewhfd';

// String to encrypt
$string 'Only a life lived for others is worth living.';

// Encrypted string
$encrypted_string key_encrypt($string$key);

// Echo output
echo '<b>Encrypted:</b> ' $encrypted_string '<br />';
echo 
'<b>Decrypted:</b> ' key_decrypt($encrypted_string$key) . '<br />'
Also read: http://us2.php.net/manual/en/ref.mcrypt.php
__________________

Please login or register to view this content. Registration is FREE

Programming is like sex: sure, it may give some practical results, but that's not why we do it.
Tekime is offline
Reply With Quote
View Public Profile Visit Tekime's homepage!
 
Reply     « Reply to two-way encryption?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.40897 seconds with 12 queries