I want to make one function like It should have some secret key to mix with so that one one can break it
function encrypt($string)
{
$key ="mastermind"
return encryptfunc($string,$key)
}
ve şifre çözme için aynı şey
PHP> = 5.3 kullanıyorsanız, yeni openssl_encrypt
a> size yardımcı olabilir: bu şifre yöntemleri geniş bir yelpazede kullanarak veri şifreleme sağlar.
Bu veriler daha sonra openssl_decrypt
a>, belli ki, tam tersini yapar, hangi ile çözülebilir.
And if you want to know which cypher functions you can use, openssl_get_cipher_methods
will be helpful ;-)
There is quite a lot of those, it seems ^^
Burada bir süre önce benim blogda yayınlanan bir kod kısmı var, yani bu üç fonksiyonlarının kullanımını göstermek gerekir:
$methods = openssl_get_cipher_methods();
var_dump($methods);
$texteACrypter = "he who doesn't do anything, doesn't go wrong -- Zeev Suraski";
$clefSecrete = "glop";
echo '<pre>';
foreach ($methods as $method) {
$encrypted = openssl_encrypt($texteACrypter, $method, $clefSecrete);
$decrypted = openssl_decrypt($encrypted, $method, $clefSecrete);
echo $method . ' : ' . $encrypted . ' ; ' . $decrypted . "\n";
}
echo '</pre>';
Bu yazma zaman var çıkış gibi bir şey oldu:
bf-ecb : /nyRYCzQPE1sunxSBclxXBd7p7gl1fUnE80gBCS1NM4s3wS1Eho6rFHOOR73V9UtnolYW+flbiCwIKa/DYh5CQ== ; he who doesn't do anything, doesn't go wrong -- Zeev Suraski
bf-ofb : M9wwf140zhwHo98k8sj2MEXdogqXEQ+TjN81pebs2tmhNOsfU3jvMy91MBM76dWM7GVjeh95p8oDybDt ; he who doesn't do anything, doesn't go wrong -- Zeev Suraski
cast5-cbc : xKgdC1y654PFYW1rIjdevu8MsQOegvJoZx0KmMwb8aCHFmznxIQVy1yvAWR3bZztvGCGrM84WkpbG33pZcxUiQ== ; he who doesn't do anything, doesn't go wrong -- Zeev Suraski
cast5-cfb : t8ABR9mPvocRikrX0Kblq2rUXHiVnA/OnjR/mDJDq8+/nn6Z9yfPbpcpRat0lYqfVAcwlypT4A4KNq4S ; he who doesn't do anything, doesn't go wrong -- Zeev Suraski
cast5-ecb : xKgdC1y654NIzRl9gJqbhYKtmJoXBoFpgLhwgdtPtYB7VZ1tRHLX0MjErtfREMJBAonp48zngSiTKlsKV0/WhQ== ; he who doesn't do anything, doesn't go wrong -- Zeev Suraski
cast5-ofb : t8ABR9mPvofCv9+AKTcRO4Q0doYlavn8zRzLvV3dZk0niO7l20KloA4nUll4VN1B5n89T/IuGh9piPte ; he who doesn't do anything, doesn't go wrong -- Zeev Suraski
des-cbc : WrCiOVPU1ipF+0trwXyVZ/6cxiNVft+TK2+vAP0E57b9smf9x/cZlQQ4531aDX778S3YJeP/5/YulADXoHT/+Q== ; he who doesn't do anything, doesn't go wrong -- Zeev Suraski
des-cfb : cDDlaifQN+hGOnGJ2xvGna7y8+qRxwQG+1DJBwQm/4abKgdZYUczC4+aOPGesZM1nKXjgoqB4+KTxGNo ; he who doesn't do anything, doesn't go wrong -- Zeev Suraski
And if you are not using PHP 5.3, you might want to take a look to the Mcrypt section of the manual, and functions such as mcrypt_encrypt
;-)
This is an interface to the mcrypt library, which supports a wide variety of block algorithms such as DES, TripleDES, Blowfish (default), 3-WAY, SAFER-SK64, SAFER-SK128, TWOFISH, TEA, RC2 and GOST in CBC, OFB, CFB and ECB cipher modes.
İşte CBC modunda AES-128 şifreleme basit ama güvenli bir uygulamasıdır
class Cipher
{
private $securekey;
private $iv_size;
function __construct($textkey)
{
$this->iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$this->securekey = hash('sha256', $textkey, TRUE);
}
function encrypt($input)
{
$iv = mcrypt_create_iv($this->iv_size);
return base64_encode($iv . mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $this->securekey, $input, MCRYPT_MODE_CBC, $iv));
}
function decrypt($input)
{
$input = base64_decode($input);
$iv = substr($input, 0, $this->iv_size);
$cipher = substr($input, $this->iv_size);
return trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $this->securekey, $cipher, MCRYPT_MODE_CBC, $iv));
}
}
Kullanımı:
$c = new Cipher('secret key goes here');
$encrypted = $c->encrypt('secret message');
$decrypted = $c->decrypt($encrypted);
Ben bir kripto adam değilim, ama şeyler bu tür kullanın:
function crypt($dataToEncrypt){
$appKey = '%39d15#13P0£df458asdc%/dfr_A!8792*dskjfzaesdfpopdfo45s4dqd8d4fsd+dfd4s"Z1';
$td = mcrypt_module_open(MCRYPT_SERPENT, '', MCRYPT_MODE_CBC, '');
// Creates IV and gets key size
$iv = mcrypt_create_iv(mcrypt_enc_get_iv_size($td), MCRYPT_DEV_RANDOM);
$ks = mcrypt_enc_get_key_size($td);
// Creates key from application key
$key = substr($appKey, 0, $ks);
// Initialization
mcrypt_generic_init($td, $key, $iv);
// Crypt data
$encrypted = mcrypt_generic($td, $dataToEncrypt);
// Close
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return array($encrypted, $iv);
}
Eğer anahtar ve başlatma vektörü gereken bir dize şifresini ($iv
).
function decrypt($encryptedData, $iv){
$appKey = '%39d15#13P0£df458asdc%/dfr_A!8792*dskjfzaesdfpopdfo45s4dqd8d4fsd+dfd4s"Z1';
$td = mcrypt_module_open(MCRYPT_SERPENT, '', MCRYPT_MODE_CBC, '');
// Gets key size
$ks = mcrypt_enc_get_key_size($td);
// Creates key from application key
$key = substr($appKey, 0, $ks);
// Initialization
mcrypt_generic_init($td, $key, $iv);
// Decrypt data
$decrypted = mdecrypt_generic($td, $encryptedData);
// Close
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
return trim($decrypted);
}
Bu PHP fonksiyonları deneyin convert_uuencode ve convert_uudecode:
Bu çok basit ve PHP yüklü kütüphaneleri bağlı değildir
function encrypt_decrypt ($data, $encrypt) {
if ($encrypt == true) {
$output = base64_encode (convert_uuencode ($data));
} else {
$output = convert_uudecode (base64_decode ($data));
}
return $output;
}
$enc_txt = encrypt_decrypt ("PASSWORD TEXT", true);
echo $enc_txt."\n";
// LTQkJTM0VT0vNEQwQDUkNTg1YGBgCmAK
echo encrypt_decrypt ($enc_txt, false);
// PASSWORD TEXT