How to decrypt data from an array codeigniter3

0

It happens that it encrypts some records with the 'encryption' library before saving them, until there, all good.

I do the query and all the data is encrypted.

What I want is to remove the encryption in the controller, before putting them in the array and passing them to the view.

(Cards are encrypted from the database)

public function card_list()
{

  $id_user    = $this->tank_auth->get_user_id();
  $this->db->where('id_user', $id_user);
  $query = $this->db->get("cards");


  $data = [];


  foreach($query->result() as $r) {

       $data[] = array(


            $r->card_owner,
            $r->card_number,
            $r->card_mm,
             $r->card_aa,
            $r->card_tag,


       );
  }



}
    
asked by Maicol Romero 12.04.2018 в 21:09
source

1 answer

1

Well I put a little wider my answer, to decrypt the data and send it to the view would be something like this

<?php
class Base extends CI_Controller
{
    public function __construct(){
        parent::__construct();
    }

    public function index(){

        $data = [
            'tarjeta'   =>  $this->card_list()
        ];

        $this->load->view('vista',$data);//Aqui pasamos la data de la funcion a la vista
    }


    public function card_list()
    {

        $id_user    = $this->tank_auth->get_user_id();
        $this->db->where('id_user', $id_user);
        $query = $this->db->get("cards");


        $data = [];


        foreach($query->result() as $r) {

            $data[] = array(
                    $this->encryption->decrypt($r->card_owner),
                    $this->encryption->decrypt($r->card_number),
                    $this->encryption->decrypt($r->card_mm),
                    $this->encryption->decrypt($r->card_aa),
                    $this->encryption->decrypt($r->card_tag),
            );
        }

        return $data;

    }
}
    
answered by 12.04.2018 в 21:53