How do I describe data in a laravel blade?

1

I have a data that comes from the encrypted controller, this with the intention that the user does not see a data that I bring from the controller, I do not know if there is another way to do this.

The data is encrypted as follows:

$valores = Respuesta::select(array(
    'respuestas.id',
    'respuestas.puntaje as punt_resp',
    'respuestas.v_f as v_f_resp',
    'respuestas.seleccion as seleccion_resp',
    'respuestas.desarrollo as desarrollo_resp',
    'preguntas.descrip',
    'preguntas.numero',
    'preguntas.tipo',
    'preguntas.puntaje as punt_preg',
    'preguntas.v_f as v_f_preg',
    'preguntas.seleccion as seleccion_preg',
    'preguntas.desarrollo as desarrollo_preg',
));

foreach($valores as $clave => $elemento){
    if($valores[$clave]["punt_resp"]){
        $valores[$clave]["punt_resp"] = Crypt::encrypt( $valores[$clave]["punt_resp"] );
    }
    if($valores[$clave]["v_f_preg"]){
        $valores[$clave]["v_f_preg"] = Crypt::encrypt( $valores[$clave]["v_f_preg"] );
    }
}

The column where the json of the encrypted data is stored in a variable and I go through it to decrypt the data, this in the following way:

let array = data[10];
for(var i=0;i(menor que)array.length;i++){ //coloco "menor que" para indicar la condicion en el "for", sucede que la web me elimina todo lo siguiente al signo "menor que"
   array[i].punt_resp = '{{ \Crypt::decrypt( array[i].punt_resp ) }}';
}

This gives me the following error:

  

syntax error, unexpected '[', expecting '('

NOTE:

This to prevent the user from seeing it like this:

Encryption is as follows:

    
asked by Pablo Contreras 30.07.2017 в 03:58
source

2 answers

0

I have not tried it, but according to a SO answer in English , it is possible to do something with an old project of Google: CryptoJS

  • Put in the .env file:

    APP_KEY=uberkeythatrocks
    
  • Put in config / app.php:

    'cipher' => 'AES-256-CBC'
    
  • On the controller:

    $mySecret = "Something I wanna hide from them";
    $encrypted = Crypt::encrypt($mySecret);
    
  • In the view, in JS:

    var key = "uberkeythatrocks";
    var decrypted = CryptoJS.AES.decrypt(encrypted, key);
    var readable = decrypted.toString(CryptoJS.enc.Utf8);
    
  • IMPORTANT: 'key' in PHP must be the same 'key' in JS, and 'cipher' in PHP must be the same in JS, however CryptoJS will automatically select AES-128-CBC or AES-256-CBC according to the length of 'key'.

        
    answered by 30.07.2017 / 17:35
    source
    0

    If you want the user not to see it, do not send it to him, neither in clear nor encrypted. If you send it encrypted and then decrypt it, you will have to send the decryption key or function; with what an advanced user can always see, dedicating time and desire.

    You can send an identifier to a value stored on the server or something similar. But whatever you send to the browser, you have lost control over it.

        
    answered by 30.07.2017 в 15:36