public function listar()
 {
     $dql = 'SELECT m, u.apelido FROM Models\\Mensagem m ' . 'JOIN m.usuario u ORDER BY m.dataTs DESC';
     $messages = $this->em->createQuery($dql)->setMaxResults(10)->getResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);
     $s = Container::getSession();
     $k = $s->get("key");
     $iv = $s->get("iv");
     foreach ($messages as $msg) {
         $encrypted = mcrypt_encrypt(MCRYPT_3DES, safeHexToString($k), trim($msg[0]["conteudo"]), MCRYPT_MODE_CBC, safeHexToString($iv));
         $item = ["nick" => trim($msg["apelido"]), "mensagem" => stringToHex($encrypted), "hora" => $msg[0]["dataTs"]->format('d/m/y H:i:s')];
         $resp[] = $item;
     }
     echo json_encode($resp, JSON_UNESCAPED_UNICODE);
     return "";
 }
 public function postEnviarMensagem(Router $r)
 {
     $r->post("/ajax/ControleMensagem/enviar/*/*", function ($userID, $txtmsg) {
         $s = Container::getSession();
         $k = safeHexToString($s->get("key"));
         $iv = safeHexToString($s->get("iv"));
         $em = Container::gerEntityManager();
         $mc = new ControleMensagem($em);
         $rp = $em->getRepository('Models\\Usuario');
         $u = $rp->findBy(["usId" => $userID]);
         $user = $u[0];
         $msg = new Mensagem();
         $decrypted = mcrypt_decrypt(MCRYPT_3DES, $k, hexToString($txtmsg), MCRYPT_MODE_CBC, $iv);
         $mc->enviar($msg, $user, $decrypted);
     });
 }
Exemple #3
0
<?php

require 'vendor/autoload.php';
require_once __DIR__ . '/src/Library/cypher3des.php';
use Library\Container;
$jsrc = Container::getCrytoParams();
extract($jsrc);
echo safeHexToString($k);