Exemple #1
0
function enc_file($file, $key)
{
    if (filesize($file) == 0) {
        echo "File {$file} Needn't Encrypt !";
        return;
    }
    $fp_r = fopen("{$file}", "rb");
    $fp_w = fopen("enc_{$file}", "wb");
    if (!$fp_r || !$fp_w) {
        die("Cannot Read or Write File !");
    }
    $enc_text = md5($key);
    fwrite($fp_w, $enc_text);
    while (!feof($fp_r)) {
        $data = fread($fp_r, 1024);
        $enc_text = enc_str($data, $key);
        fwrite($fp_w, $enc_text);
    }
    fclose($fp_r);
    fclose($fp_w);
    unlink($file);
    rename("enc_{$file}", $file);
    return;
}
$mail->addAddress('*****@*****.**', 'Mark Raymund Tejero');
//Set the subject line
$mail->Subject = 'RE: PHPMailer sendmail test';
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//send the message, check for errors
if (!$mail->send()) {
    echo "<br>Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "<br>Message sent!";
}
echo "\n<hr>STR:<hr>\n'{$raw}'\n<hr>\n{$method}\n<hr>\n{$pass}\n<hr>\nENC: {$enc}\n<hr>\nDEC: '{$dec}'\n";
if (0) {
    $str1 = enc_str('mark-tejero');
    $str2 = dec_str($str1);
    echo "\n{$str1}\n<hr>\n{$str2}\n<hr>\n";
    function enc_str($str, $key = '1234567890!')
    {
        $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_DEV_URANDOM);
        $encrypted = base64_encode($iv . mcrypt_encrypt(MCRYPT_RIJNDAEL_128, hash('sha256', $key, true), $str, MCRYPT_MODE_CBC, $iv));
        echo "ENCRYPT> {$str} -> \${$encrypted}\n";
        return $encrypted;
    }
    function dec_str($str, $key = '1234567890!')
    {
        $data = base64_decode($str);
        $iv = substr($data, 0, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC));
        $decrypted = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, hash('sha256', $key, true), substr($data, mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC)), MCRYPT_MODE_CBC, $iv), "");
        echo "DECRYPT> {$str} -> \${$decrypted}\n";
Exemple #3
0
function change_pwd($pwd)
{
    $sql = "update m set psw='" . enc_str($pwd) . "'";
    qexec($sql);
}