집 >
기사 > 백엔드 개발 > PHP 암호화 및 복호화 처리 클래스--참조: Discuz Forum의 Passport_PHP 튜토리얼
PHP 암호화 및 복호화 처리 클래스--참조: Discuz Forum의 Passport_PHP 튜토리얼
- WBOY원래의
- 2016-07-22 09:03:051024검색
<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">참</span><span id="isBasedOnUrl" itemprop="isBasedOnUrl">http: //www.bkjia.com/PHPjc/371817.html</span><span id="genre" itemprop="genre">기술기사</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으로 문의하세요.