首頁 >後端開發 >php教程 >php加密解密處理類別--參 考:Discuz論壇的passpor_PHP教程
php加密解密處理類別--參 考:Discuz論壇的passpor_PHP教程
- WBOY原創
- 2016-07-22 09:03:051064瀏覽
<p></p>
<p><code class="php plain"><?php </code></p>
<table>
<tbody>
<tr>
<td class="number"><code>02</code></td>
<td class="content"><code class="php comments">/*=========================================================== </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>03</code></td>
<td class="content"><code class="php comments">= 版权协议: </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>04</code></td>
<td class="content"><code class="php comments">= GPL (The GNU GENERAL PUBLIC LICENSE Version 2, June 1991) </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>05</code></td>
<td class="content"><code class="php comments">=------------------------------------------------------------ </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>06</code></td>
<td class="content"><code class="php comments">= 文件名称:cls.sys_crypt.php </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>07</code></td>
<td class="content"><code class="php comments">= 摘 要:php加密解密处理类 </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>08</code></td>
<td class="content"><code class="php comments">= 版 本:1.0 </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>09</code></td>
<td class="content"><code class="php comments">= 参 考:Discuz论坛的passport相关函数 </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>10</code></td>
<td class="content"><code class="php comments">=------------------------------------------------------------ </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>11</code></td>
<td class="content"><code class="php comments">= Script Written By PHPWMS项目组 </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>12</code></td>
<td class="content"><code class="php comments">= 最后更新:xinge </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>13</code></td>
<td class="content"><code class="php comments">= 最后日期:2007-12-09 </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>14</code></td>
<td class="content"><code class="php comments">============================================================*/</code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>15</code></td>
<td class="content"><code class="spaces"> </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>16</code></td>
<td class="content"><code class="php keyword">class</code> <code class="php plain">SysCrypt { </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>17</code></td>
<td class="content"><code class="spaces"> </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>18</code></td>
<td class="content"><code class="php keyword">private</code> <code class="php variable">$crypt_key</code><code class="php plain">; </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>19</code></td>
<td class="content"><code class="spaces"> </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>20</code></td>
<td class="content"><code class="php comments">// 构造函数 </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>21</code></td>
<td class="content"><code class="php keyword">public</code> <code class="php keyword">function</code> <code class="php plain">__construct(</code><code class="php variable">$crypt_key</code><code class="php plain">) { </code></td>
</tr>
</tbody>
</table><table>
<tbody>
<tr>
<td class="number"><code>22</code></td>
<td class="content"><code class="spaces"> </code><code class="php variable">$this</code> <code class="php plain">-> crypt_key = </code><code class="php variable">$crypt_key</code><code class="php plain">; </code>
</p>
<table>
<tbody>
<tr>
<td class="number"><code>23</code></td>
<td class="content"><code class="php plain">} </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>24</code></td>
<td class="content"><code class="spaces"> </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>25</code></td>
<td class="content">
<code class="php keyword">public</code> <code class="php keyword">function</code> <code class="php plain">php_encrypt(</code><code class="php variable">$txt</code><code class="php plain">) { </code>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>26</code></td>
<td class="content">
<code class="spaces"> </code><code class="php plain">srand((double)microtime() * 1000000); </code>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>27</code></td>
<td class="content">
<code class="spaces"> </code><code class="php variable">$encrypt_key</code> <code class="php plain">= md5(rand(0,32000)); </code>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>28</code></td>
<td class="content">
<code class="spaces"> </code><code class="php variable">$ctr</code> <code class="php plain">= 0; </code>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>29</code></td>
<td class="content">
<code class="spaces"> </code><code class="php variable">$tmp</code> <code class="php plain">= </code><code class="php string">''</code><code class="php plain">; </code>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>30</code></td>
<td class="content">
<code class="spaces"> </code><code class="php keyword">for</code><code class="php plain">(</code><code class="php variable">$i</code> <code class="php plain">= 0;</code><code class="php variable">$i</code><code class="php plain"><</code><code class="php functions">strlen</code><code class="php plain">(</code><code class="php variable">$txt</code><code class="php plain">);</code><code class="php variable">$i</code><code class="php plain"> ) { </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>31</code></td>
<td class="content"><code class="spaces"> </code><code class="php variable">$ctr</code> <code class="php plain">= </code><code class="php variable">$ctr</code> <code class="php plain">== </code><code class="php functions">strlen</code><code class="php plain">(</code><code class="php variable">$encrypt_key</code><code class="php plain">) ? 0 : </code><code class="php variable">$ctr</code><code class="php plain">; </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>32</code></td>
<td class="content"><code class="spaces"> </code><code class="php variable">$tmp</code> <code class="php plain">.= </code><code class="php variable">$encrypt_key</code><code class="php plain">[</code><code class="php variable">$ctr</code><code class="php plain">].(</code><code class="php variable">$txt</code><code class="php plain">[</code><code class="php variable">$i</code><code class="php plain">]^</code><code class="php variable">$encrypt_key</code><code class="php plain">[</code><code class="php variable">$ctr</code><code class="php plain"> ]); </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>33</code></td>
<td class="content"><code class="spaces"> </code><code class="php plain">} </code></td>
</tr>
</tbody>
</table><table>
<tbody>
<tr>
<td class="number"><code>34</code></td>
<td class="content"><code class="spaces"> </code><code class="php keyword">return</code> <code class="php functions">base64_encode</code><code class="php plain">(self::__key(</code><code class="php variable">$tmp</code><code class="php plain">,</code><code class="php variable">$this</code> <code class="php plain">-> crypt_key)); </code>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>35</code></td>
<td class="content"><code class="php plain">} </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>36</code></td>
<td class="content"><code class="spaces"> </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>37</code></td>
<td class="content">
<code class="php keyword">public</code> <code class="php keyword">function</code> <code class="php plain">php_decrypt(</code><code class="php variable">$txt</code><code class="php plain">) { </code>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>38</code></td>
<td class="content">
<code class="spaces"> </code><code class="php variable">$txt</code> <code class="php plain">= self::__key(</code><code class="php functions">base64_decode</code><code class="php plain">(</code><code class="php variable">$txt</code><code class="php plain">),</code><code class="php variable">$this</code> <code class="php plain">-> crypt_key); </code>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>39</code></td>
<td class="content">
<code class="spaces"> </code><code class="php variable">$tmp</code> <code class="php plain">= </code><code class="php string">''</code><code class="php plain">; </code>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>40</code></td>
<td class="content">
<code class="spaces"> </code><code class="php keyword">for</code><code class="php plain">(</code><code class="php variable">$i</code> <code class="php plain">= 0;</code><code class="php variable">$i</code> <code class="php plain">< </code><code class="php functions">strlen</code><code class="php plain">(</code><code class="php variable">$txt</code><code class="php plain">); </code><code class="php variable">$i</code><code class="php plain"> ) { </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>41</code></td>
<td class="content"><code class="spaces"> </code><code class="php variable">$md5</code> <code class="php plain">= </code><code class="php variable">$txt</code><code class="php plain">[</code><code class="php variable">$i</code><code class="php plain">]; </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>42</code></td>
<td class="content"><code class="spaces"> </code><code class="php variable">$tmp</code> <code class="php plain">.= </code><code class="php variable">$txt</code><code class="php plain">[ </code><code class="php variable">$i</code><code class="php plain">] ^ </code><code class="php variable">$md5</code><code class="php plain">; </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>43</code></td>
<td class="content"><code class="spaces"> </code><code class="php plain">} </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>44</code></td>
<td class="content"><code class="spaces"> </code><code class="php keyword">return</code> <code class="php variable">$tmp</code><code class="php plain">; </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>45</code></td>
<td class="content"><code class="php plain">} </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>46</code></td>
<td class="content"><code class="spaces"> </code></td>
</tr>
</tbody>
</table><table>
<tbody>
<tr>
<td class="number"><code>47</code></td>
<td class="content"><code class="php keyword">private</code> <code class="php keyword">function</code> <code class="php plain">__key(</code><code class="php variable">$txt</code><code class="php plain">,</code><code class="php variable">$encrypt_key</code><code class="php plain">) { </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>48</code></td>
<td class="content"><code class="spaces"> </code><code class="php variable">$encrypt_key</code> <code class="php plain">= md5(</code><code class="php variable">$encrypt_key</code><code class="php plain">); </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>49</code></td>
<td class="content"><code class="spaces"> </code><code class="php variable">$ctr</code> <code class="php plain">= 0; </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>50</code></td>
<td class="content"><code class="spaces"> </code><code class="php variable">$tmp</code> <code class="php plain">= </code><code class="php string">''</code><code class="php plain">; </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>51</code></td>
<td class="content"><code class="spaces"> </code><code class="php keyword">for</code><code class="php plain">(</code><code class="php variable">$i</code> <code class="php plain">= 0; </code><code class="php variable">$i</code> <code class="php plain">< </code><code class="php functions">strlen</code><code class="php plain">(</code><code class="php variable">$txt</code><code class="php plain">); </code><code class="php variable">$i</code><code class="php plain"> ) { </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>52</code></td>
<td class="content"><code class="spaces"> </code><code class="php variable">$ctr</code> <code class="php plain">= </code><code class="php variable">$ctr</code> <code class="php plain">== </code><code class="php functions">strlen</code><code class="php plain">(</code><code class="php variable">$encrypt_key</code><code class="php plain">) ? 0 : </code><code class="php variable">$ctr</code><code class="php plain">; </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>53</code></td>
<td class="content"><code class="spaces"> </code><code class="php variable">$tmp</code> <code class="php plain">.= </code><code class="php variable">$txt</code><code class="php plain">[</code><code class="php variable">$i</code><code class="php plain">] ^ </code><code class="php variable">$encrypt_key</code><code class="php plain">[</code><code class="php variable">$ctr</code><code class="php plain"> ]; </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>54</code></td>
<td class="content"><code class="spaces"> </code><code class="php plain">} </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>55</code></td>
<td class="content"><code class="spaces"> </code><code class="php keyword">return</code> <code class="php variable">$tmp</code><code class="php plain">; </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>56</code></td>
<td class="content"><code class="php plain">} </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>57</code></td>
<td class="content"><code class="spaces"> </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>58</code></td>
<td class="content"><code class="php keyword">public</code> <code class="php keyword">function</code> <code class="php plain">__destruct() { </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>59</code></td>
<td class="content"><code class="spaces"> </code><code class="php variable">$this</code> <code class="php plain">-> crypt_key = null; </code>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>60</code></td>
<td class="content"><code class="php plain">} </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>61</code></td>
<td class="content"><code class="php plain">} </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>62</code></td>
<td class="content"><code class="spaces"> </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>63</code></td>
<td class="content"><code class="spaces"> </code></td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>64</code></td>
<td class="content">
<code class="php variable">$sc</code> <code class="php plain">= </code><code class="php keyword">new</code> <code class="php plain">SysCrypt(</code><code class="php string">'phpwms'</code><code class="php plain">); </code>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>65</code></td>
<td class="content">
<code class="php variable">$text</code> <code class="php plain">= </code><code class="php string">'110'</code><code class="php plain">; </code>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>66</code></td>
<td class="content">
<code class="php plain">print(</code><code class="php variable">$sc</code> <code class="php plain">-> php_encrypt(</code><code class="php variable">$text</code><code class="php plain">)); </code>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>67</code></td>
<td class="content">
<code class="php plain">print(</code><code class="php string">'<br>'</code><code class="php plain">); </code>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>68</code></td>
<td class="content">
<code class="php plain">print(</code><code class="php variable">$sc</code> <code class="php plain">-> php_decrypt(</code><code class="php variable">$sc</code> <code class="php plain">-> php_encrypt(</code><code class="php variable">$text</code><code class="php plain">))); </code>
</td>
</tr>
</tbody>
</table>
<table>
<tbody>
<tr>
<td class="number"><code>69</code></td>
<td class="content"><code class="php plain">?></code></td>
</tr>
</tbody>
</table>
<p align="left"></p>
<div style="display:none;">
<span id="url" itemprop="url">http://www.bkjia.com/PHPjc/371817.html</span><span id="indexUrl" itemprop="indexUrl">www.bkjia.com</span><span id="isOriginal" itemprop="isOriginal">true</span><span id="isBasedOnUrl" itemprop="isBasedOnUrl">http: //www.bkjia.com/PHPjc/371817.html</span><span id="genre" itemprop="genre">TechArticle</span><span id="description" itemprop="description">?php 02 /*=================== = ====== =========================================== 03 = 預設:04 = GPL(GNU 通用公共授權第2 版,1991 年6 月)05 =----------------------------- ----...</span>
</div>
<div class="art_confoot"></div>
陳述:本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn