Maison php教程 php手册 php自定义加密函数、解密的例子

php自定义加密函数、解密的例子

May 25, 2016 pm 04:45 PM
php加密函数 php解密

加密就是将一些字符转换为另一个字符串的过程,简单的说就是把大门上锁,并且只有你有开启的钥匙,作为一个程序员都应该有属于自己的加密方式,目前最流行的加密算法就是MD5()加密方式,但是在网站已经有了破解的软件用起来也不是很安全,下面简单的介绍一下自定义的加密函数,代码如下:

<?php
/*加密*/
function addcoder($str) {
    $yuan = &#39;abA!c1dB#ef2@Cg$h%iD_3jkl^E:m}4n.o{&F*p)5q(G-r[sH]6tuIv7w+Jxy8z9K0&#39;;
    $jia = &#39;zAy%0Bx+1C$wDv^Eu2-t3(F{sr&G4q_pH5*on6I)m:l7.Jk]j8K}ih@gf9#ed!cb[a&#39;;
    if (strlen($str) == 0) return false;
    for ($i = 0; $i < strlen($str); $i++) {
        for ($j = 0; $j < strlen($yuan); $j++) {
            if ($str[$i] == $yuan[$j]) {
                $results.= $jia[$j];
                break;
            }
        }
    }
    return $results;
}
/*解密*/
function removecoder($str) {
    $yuan = &#39;abA!c1dB#ef2@Cg$h%iD_3jkl^E:m}4n.o{&F*p)5q(G-r[sH]6tuIv7w+Jxy8z9K0&#39;;
    $jia = &#39;zAy%0Bx+1C$wDv^Eu2-t3(F{sr&G4q_pH5*on6I)m:l7.Jk]j8K}ih@gf9#ed!cb[a&#39;;
    If (strlen($str) == 0) return false;
    for ($i = 0; $i < strlen($str); $i++) {
        for ($j = 0; $j < strlen($jia); $j++) {
            if ($str[$i] == $jia[$j]) {
                $results.= $yuan[$j];
                break;
            }
        }
    }
    return $results;
}
$str = "www.phprm.com";
echo "加密前:" . $str . "<br >";
$str1 = addcoder($str);
echo "加密后:" . $str1 . "<br >";
$str2 = removecoder($str1);
echo "解密后:" . $str2 . "<br >";
?>
Copier après la connexion

例子二,利用md5+base64_encode进行编辑处理,代码如下:

<?php
//
function passport_encrypt($txt, $key) {
    srand((double)microtime() * 1000000);
    $encrypt_key = md5(rand(0, 32000));
    $ctr = 0;
    $tmp = &#39;&#39;;
    for ($i = 0; $i < strlen($txt); $i++) {
        $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
        $tmp.= $encrypt_key[$ctr] . ($txt[$i] ^ $encrypt_key[$ctr++]);
    }
    return base64_encode(passport_key($tmp, $key));
}
function passport_decrypt($txt, $key) {
    $txt = passport_key(base64_decode($txt) , $key);
    $tmp = &#39;&#39;;
    for ($i = 0; $i < strlen($txt); $i++) {
        $md5 = $txt[$i];
        $tmp.= $txt[++$i] ^ $md5;
    }
    return $tmp;
}
function passport_key($txt, $encrypt_key) {
    $encrypt_key = md5($encrypt_key);
    $ctr = 0;
    $tmp = &#39;&#39;;
    for ($i = 0; $i < strlen($txt); $i++) {
        $ctr = $ctr == strlen($encrypt_key) ? 0 : $ctr;
        $tmp.= $txt[$i] ^ $encrypt_key[$ctr++];
    }
    return $tmp;
}
?>
Copier après la connexion


本文链接:

收藏随意^^请保留教程地址.

Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn

Outils d'IA chauds

Undresser.AI Undress

Undresser.AI Undress

Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover

AI Clothes Remover

Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool

Undress AI Tool

Images de déshabillage gratuites

Clothoff.io

Clothoff.io

Dissolvant de vêtements AI

AI Hentai Generator

AI Hentai Generator

Générez AI Hentai gratuitement.

Article chaud

R.E.P.O. Crystals d'énergie expliqués et ce qu'ils font (cristal jaune)
2 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
Repo: Comment relancer ses coéquipiers
4 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: Comment obtenir des graines géantes
3 Il y a quelques semaines By 尊渡假赌尊渡假赌尊渡假赌
Combien de temps faut-il pour battre Split Fiction?
3 Il y a quelques semaines By DDD

Outils chauds

Bloc-notes++7.3.1

Bloc-notes++7.3.1

Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise

SublimeText3 version chinoise

Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1

Envoyer Studio 13.0.1

Puissant environnement de développement intégré PHP

Dreamweaver CS6

Dreamweaver CS6

Outils de développement Web visuel

SublimeText3 version Mac

SublimeText3 version Mac

Logiciel d'édition de code au niveau de Dieu (SublimeText3)