You are here: Re: How do I encrypt a string? « PHP Programming Language « IT news, forums, messages
Re: How do I encrypt a string?

Posted by BKDotCom on 11/07/49 11:31

what kind of key do you need?
a simple encrypt/decrypt key, or a public/private key?

here's blowfish encryption using the mcrypt library

// returns base64_encoded string
function encrypt_blowfish($key,$data)
{
$mode = MCRYPT_MODE_CBC;
$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, $mode);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$encrypted = $iv.mcrypt_encrypt(MCRYPT_BLOWFISH, $key, $data,
$mode, $iv);
$encrypted = base64_encode($encrypted);
return $encrypted;
}

// encrypted should be base64_encoded
function decrypt_blowfish($key,$encrypted)
{
$mode = MCRYPT_MODE_CBC;
$iv_size = mcrypt_get_iv_size(MCRYPT_BLOWFISH, $mode);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$encrypted = base64_decode($encrypted);
$decrypted = substr(trim(mcrypt_decrypt(MCRYPT_BLOWFISH, $key,
$encrypted, $mode, $iv),"\0"),$iv_size);
return $decrypted;
}

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация