2016-04-13 63 views
-3

çökmesini sebepten dolayı .php çalışmıyor. İşte benim kodum. Sana include 'AES.php's; değişiklik include 'AES.php'; için sağladığınız örnek ve çalışma ile kontrol ettikten kullandık http://aesencryption.net/#PHP-aes-encryption-exampleAES şifreleme php benim webserver

<?php 
    include 'AES.php's; 
    $inputText = "My text to encrypt"; 
    $inputKey = "My text to encrypt"; 
    $blockSize = 256; 
    $aes = new AES($inputText, $inputKey, $blockSize); 
    $enc = $aes->encrypt(); 
    $aes->setData($enc); 
    $dec=$aes->decrypt(); 
    echo "After encryption: ".$enc."<br/>"; 
    echo "After decryption: ".$dec."<br/>"; 
    ?> 

üzerinde ve bana İlk satırda 404

+0

, 'AES.php'yi içerir; –

+3

Cinsellik için ekstra s? –

cevap

0

verir nedense bulundu örneği kullanıyordum Ben senin Örneğin göre yanlış sözdizimi Aşağıda

<?php 
include 'aes.php'; 
$inputText = "My text to encrypt"; 
$inputKey = "My text to encrypt"; 
$blockSize = 256; 
$aes = new AES($inputText, $inputKey, $blockSize); 
$enc = $aes->encrypt(); 
$aes->setData($enc); 
$dec=$aes->decrypt(); 
echo "After encryption: ".$enc."<br/>"; 
echo "After decryption: ".$dec."<br/>"; 
?> 

olduğunu aes.php değişince http://aesencryption.net/#PHP-aes-encryption-example

nedense indeksi .php için aes.php

/** 
Aes encryption 
*/ 
class AES { 

    const M_CBC = 'cbc'; 
    const M_CFB = 'cfb'; 
    const M_ECB = 'ecb'; 
    const M_NOFB = 'nofb'; 
    const M_OFB = 'ofb'; 
    const M_STREAM = 'stream'; 

    protected $key; 
    protected $cipher; 
    protected $data; 
    protected $mode; 
    protected $IV; 
/** 
* 
* @param type $data 
* @param type $key 
* @param type $blockSize 
* @param type $mode 
*/ 
    function __construct($data = null, $key = null, $blockSize = null, $mode = null) { 
    $this->setData($data); 
    $this->setKey($key); 
    $this->setBlockSize($blockSize); 
    $this->setMode($mode); 
    $this->setIV(""); 
    } 

/** 
* 
* @param type $data 
*/ 
    public function setData($data) { 
    $this->data = $data; 
    } 

/** 
* 
* @param type $key 
*/ 
    public function setKey($key) { 
    $this->key = $key; 
    } 

/** 
* 
* @param type $blockSize 
*/ 
    public function setBlockSize($blockSize) { 
    switch ($blockSize) { 
     case 128: 
     $this->cipher = MCRYPT_RIJNDAEL_128; 
     break; 

     case 192: 
     $this->cipher = MCRYPT_RIJNDAEL_192; 
     break; 

     case 256: 
     $this->cipher = MCRYPT_RIJNDAEL_256; 
     break; 
    } 
    } 

/** 
* 
* @param type $mode 
*/ 
    public function setMode($mode) { 
    switch ($mode) { 
     case AES::M_CBC: 
     $this->mode = MCRYPT_MODE_CBC; 
     break; 
     case AES::M_CFB: 
     $this->mode = MCRYPT_MODE_CFB; 
     break; 
     case AES::M_ECB: 
     $this->mode = MCRYPT_MODE_ECB; 
     break; 
     case AES::M_NOFB: 
     $this->mode = MCRYPT_MODE_NOFB; 
     break; 
     case AES::M_OFB: 
     $this->mode = MCRYPT_MODE_OFB; 
     break; 
     case AES::M_STREAM: 
     $this->mode = MCRYPT_MODE_STREAM; 
     break; 
     default: 
     $this->mode = MCRYPT_MODE_ECB; 
     break; 
    } 
    } 

/** 
* 
* @return boolean 
*/ 
    public function validateParams() { 
    if ($this->data != null && 
     $this->key != null && 
     $this->cipher != null) { 
     return true; 
    } else { 
     return FALSE; 
    } 
    } 

    public function setIV($IV) { 
     $this->IV = $IV; 
    } 
    protected function getIV() { 
     if ($this->IV == "") { 
     $this->IV = mcrypt_create_iv(mcrypt_get_iv_size($this->cipher, $this->mode), MCRYPT_RAND); 
     } 
     return $this->IV; 
    } 

/** 
* @return type 
* @throws Exception 
*/ 
    public function encrypt() { 

    if ($this->validateParams()) { 
     return trim(base64_encode(
     mcrypt_encrypt(
      $this->cipher, $this->key, $this->data, $this->mode, $this->getIV()))); 
    } else { 
     throw new Exception('Invlid params!'); 
    } 
    } 
/** 
* 
* @return type 
* @throws Exception 
*/ 
    public function decrypt() { 
    if ($this->validateParams()) { 
     return trim(mcrypt_decrypt(
     $this->cipher, $this->key, base64_decode($this->data), $this->mode, $this->getIV())); 
    } else { 
     throw new Exception('Invlid params!'); 
    } 
    } 

} 
+0

Teşekkürler ama bu benim için işe yaradı. senin AES.php nerede saklanır? –

+0

@EliasBothell haha ​​.. o zaman örnekte ne yapıyorsunuz ve kodunuza dahil etmeye çalışıyorsunuz. Örnek bağlantıdan aldığım aes.php dosyasıyla düzenlediğim herhangi bir yol –