Welcome Guest, Not a member yet? Register   Sign In
How to use AES in ci?
#1

[eluser]Turn_right[/eluser]
I want to use AES encryption,But always run some error.

I downloaded the AES free version opensorce code in phpAES

In general,I used in following way:
Code:
$z=md5($key);
$aes = new AES($z);

$z is the key of AES.

==========
Use in CI:

I put the AES.php to library/
and go to system_model to use.

Code:
$z=md5($key); $this->load->library('AESclass',$z);

But run some error like:
Quote:A PHP Error was encountered
Severity: Warning

Message: Missing argument 1 for AES::__construct(), called in C:\AppServ\www\CodeIgniter\system\core\Loader.php on line 950 and defined

Filename: libraries/AES.php

Line Number: 184

Quote:A PHP Error was encountered
Severity: Notice

Message: Undefined variable: z

Filename: libraries/AES.php

Line Number: 185


I don't know how to put the key ....

Confusedhut:
#2

[eluser]ηυмвєяσηє[/eluser]
dunno about aes class but the usage of libraries in codeigniter is like
Code:
$this->load->library('AESclass','aes');

$aeskey = $this->aes->encrypt($z);

u may need to modify the library.
#3

[eluser]Turn_right[/eluser]
But in AES.php
Code:
public function __construct($z) {
              ...........
              ...........
        }

$z is the key ,isn't?

When I put key , I can use like

Code:
$aes = New AES($z);
$cipher = $aes->encrypt($item);

$item is something that I want to encrypt.


in Manual:
Code:
$params = array('type' => 'large', 'color' => 'red');

$this->load->library('Someclass', $params);

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Someclass {

    public function __construct($params)
    {
        // Do something with $params
    }
}

?>


as you say
Code:
$this->load->library('AES','aes');

is aes the key?


I mess up .... :down:
#4

[eluser]ηυмвєяσηє[/eluser]
try this.
Code:
$this->load->library('AESclass');
$aeskey = $this->aesclass->encrypt($keyvalue);
#5

[eluser]Turn_right[/eluser]
Ah.... Is my explain unclear?, or....

AES is a symmetric-key encryption standard adopted.

You have to give a key to encrypt the item you want to be a secret.

in general,use that class.

Only if you give a key ,you can use function including encrypt or decrypt.


as you say
Code:
$aeskey = $this->aesclass->encrypt($keyvalue);
It is just use the encrypt function,still does not give a key.

Would you explain why are you use that way?

Maybe is my fault.... :blank:
#6

[eluser]InsiteFX[/eluser]
Code:
class Aes {

    private $secret_key;

    public function __construct($key_value)
    {
        parent::__construct();

        // Do something with $params
        $this->secret_key = $key_value;
    }
}

InsiteFX
#7

[eluser]Turn_right[/eluser]
I just want to load the AES.php to my model

Should i modify the AES.php?
#8

[eluser]Turn_right[/eluser]
Thanks Big Grin

finally , I solved the problem to modify the AES.php .
#9

[eluser]InsiteFX[/eluser]
If you are using AES for encrypting to the database, AES is a MySQL Command!

No need for a library, read the MySQL documentation!

InsiteFX
#10

[eluser]Turn_right[/eluser]
gooooooood!!!!!!!

Thanks for your suggestion!!
:bug:




Theme © iAndrew 2016 - Forum software by © MyBB