程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php對稱加密算法的例子

php對稱加密算法的例子

編輯:關於PHP編程

分享下php對稱加密算法的實現代碼。

KEY 是之前定義的常量

Mcrypt::::('ROOT') or ('Access Denied'   encrypt( (mcrypt_encrypt(MCRYPT_RIJNDAEL_256, (), , MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB),   decrypt( mcrypt_decrypt(MCRYPT_RIJNDAEL_256, (), (), MCRYPT_MODE_ECB, mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB),

xcrypt.php

 
      
  __construct(,  = 'cbc',  = "off" (( 8: 
->mcrypt = 16: 
->mcrypt = 32: 
->mcrypt =: 
("Key size must be 8/16/32".jbxue.-> =  (( 'ofb': 
->mode = ( == 'off') ('OFB must give a IV'); 
 'cfb': 
->mode = ( == 'off') ('CFB must give a IV'); 
 'ecb': 
->mode = = 'off'; 
 'cbc': 
: 
->mode = (( "off": 
->iv =  "auto": 
 = =='WINNT' ? MCRYPT_RAND :->iv = mcrypt_create_iv(mcrypt_get_block_size(->mcrypt, ->mode), : 
->iv =   www.jbxue.  getIV( = 'base64' ( 'base64': 
 = (-> 'hex': 
 = (-> 'bin': 
: 
 = ->  
  encrypt(,  = 'base64' (->mcrypt == MCRYPT_DES)  = ->_pkcs5Pad( ((-> = mcrypt_encrypt(->mcrypt, ->, , ->mode, -> = mcrypt_encrypt(->mcrypt, ->, , -> ( 'base64': 
 = ( 'hex': 
 = ( 'bin': 
: 
 =   
  decrypt(,  = "base64" =  ( 'base64': 
 = ( 'hex': 
 = ->_hex2bin( 'bin': 
: ( !==  ((-> = mcrypt_decrypt(->mcrypt, ->, , ->mode, -> = mcrypt_decrypt(->mcrypt, ->, , -> (->mcrypt == MCRYPT_DES)  = ->_pkcs5Unpad( = (   _pkcs5Pad(->blocksize = mcrypt_get_block_size(->mcrypt, -> = ->blocksize - (() % ->  . ((),   _pkcs5Unpad( = ({() - 1 ( > ())   ((, (), () - ) != )   = (, 0, -1 *    _hex2bin( =  =  !==  && ('/^[0-9a-fA-F]+$/i', ) ? ("H*", ) :  

<?('Content-Type:text/html;Charset=utf-8;' "xcrypt.php" '<pre>' = (['a']) ? ['a'] : '測試123'
 = '12345678123456781234567812345678'; 
 = '1234567812345678'; 
 = '12345678'; 
 =  Xcrypt(, 'cbc', 'auto'
 '向量:'(->
 = ->encrypt(, 'base64'
 = ->decrypt(, 'base64' '加密後:'( '解密後:'( '</pre>';

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved