Şifrelemek için nasıl / php ile dosyadan metin şifresini?
if you have mcrypt module compiled with your PHP:
function encryptData($value){
$key = "top secret key";
$text = $value;
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
return $crypttext;
}
function decryptData($value){
$key = "top secret key";
$crypttext = $value;
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$decrypttext = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $crypttext, MCRYPT_MODE_ECB, $iv);
return trim($decrypttext);
}
$filename = "/usr/local/something.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
$EncryptedData=encryptData($content);
$DecryptedData=decryptData($EncryptedData);
Daha fazla bilgi için http://us3.php.net/manual/en/function.mcrypt-encrypt.php bakın. (Kod parçacıkları aynı kaynaktan)
Burada temel DES şifreleme
<?php
$key = 'yourSecretKey';
$plain_text = pkcs5_pad(file_get_contents('yourFile.txt'));
/* Open module, and create IV */
$td = mcrypt_module_open(MCRYPT_DES, '', MCRYPT_MODE_CBC, '');
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = mcrypt_create_iv($iv_size, MCRYPT_DEV_URANDOM);
/* Initialize encryption handle */
mcrypt_generic_init($td, $key, $iv);
/* Encrypt data */
$encrypted = mcrypt_generic($td, $plain_text);
mcrypt_generic_deinit($td);
file_put_contents('yourFile.txt.enc', $encrypted);