From: Nicolas Boisselier Date: Tue, 6 Dec 2016 10:50:09 +0000 (+0000) Subject: cryptkey X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=5969f58c26b0b218a306b59eb85d22c24c1f2af9;p=nb.git cryptkey --- diff --git a/lib/php/nb.php b/lib/php/nb.php index 85090a28..5e80a6f8 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -835,8 +835,11 @@ class NB { return str_pad($input,$pad_length-$mb_diff,$pad_string,$pad_type); } + public static function cryptkey($length=32) { + return bin2hex(mcrypt_create_iv($length, MCRYPT_DEV_URANDOM)); + } + public static function encrypt($key,$value) { - #$key = hash("SHA256", 'your pass', true); //we want a 32 byte binary blob $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND); return base64_encode($iv . mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $value, MCRYPT_MODE_CBC, $iv)); @@ -858,7 +861,7 @@ return; if (!count($argv) or (string)$argv[1] != 'test') return; $value = 'Hello World !'; #$value = file_get_contents('/etc/hosts'); -$key = hash("SHA256", '5587eeb68760aa0ed7d2d1212d0829c3', true); //we want a 32 byte binary blob +$key = hash("MD5", '5587eeb68760aa0ed7d2d1212d0829c3'); //we want a 32 byte binary blob #$key = '5587eeb68760aa0ed7d2d1212d0829c3'; #$key = '76a553babab7a62b7935d9a10f73777bf57b043c9d0f1fc22ea51dd9484154bc91afafd0f92e773e590ad05ebca9aec3fac11ebada7e517c78d32790e5a8f3ed'; $enc = nb::encrypt($key,$value); diff --git a/www/dbq/dbq.php b/www/dbq/dbq.php index 0f4d8d26..ccfc2584 100644 --- a/www/dbq/dbq.php +++ b/www/dbq/dbq.php @@ -10,6 +10,7 @@ function dbq_run() { 'db' => 'ls', 'table' => 'ls', 'action' => 'ls', + 'params' => '', ]); #var_export($params); $ext = $params['format']; @@ -24,7 +25,7 @@ function dbq_run() { #Page::pdef('out',1); $Page = new Page([ 'css' => '/default.css', - 'title' => join(' ',array_unique(array_slice(array_values($params),1))), + 'title' => join(' ',array_filter(array_unique(array_slice(array_values($params),1)),function($v){if ($v!=='ls') return $v;})), ]); $params['ext'] = $ext; @@ -74,7 +75,6 @@ function dbq_run() { # # Db actions if ($params['table'] == 'help') { - #$this->out->rows($format,$rows,$head); $Db->out([ [ 'help', 'This help' ], [ 'ls', 'List tables' ], @@ -85,15 +85,6 @@ function dbq_run() { return $Page->end(); } elseif ($params['table'] == 'ls') { - /* - bye('zaza'); - $Table->row_parse_post = function(&$row) use($Page) { - debug($row); - $row['name'] = ''; - #$Page->tag('a',$row['name']); - }; - */ - #$Db->action('db.tables'); $Db->out($Db->tables_rows(),[],['row_parse_post'=>function(&$r) use ($Page,$params) { $r['name'] = $Page->tag('a',$r['name'],'href="'.$params['db'].'/'.$r['name'].'.'.$params['ext'].'"'); }]); @@ -124,7 +115,7 @@ function dbq_run() { [ 'fields', 'List fields' ], ],['command','description'], ['row_parse_post'=>function(&$r) use ($Page,$params) { - $r['command'] = $Page->tag('a',$r['command'],'href="'.$r['command'].'.'.$params['ext'].'"'); + $r['command'] = $Page->tag('a',$r['command'],'href="'.($r['command']=='ls'?'../'.$params['table']:$r['command']).'.'.$params['ext'].'"'); }]); return $Page->end();