From: Nicolas Boisselier Date: Mon, 31 Oct 2016 02:09:50 +0000 (+0000) Subject: encrypt, fix text eol X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=8b7ae0b891aff61b86683a6363bc04803651bbb9;p=nb.git encrypt, fix text eol --- diff --git a/lib/php/db.php b/lib/php/db.php index 8d74357f..173bec36 100644 --- a/lib/php/db.php +++ b/lib/php/db.php @@ -1094,7 +1094,6 @@ class Db extends nb { } # Set format from client Accept if != html - #bye(out::client_type()); Db::pdef('format',out::client_type()); } diff --git a/lib/php/db/table.php b/lib/php/db/table.php index 8b899489..9ed3b6c1 100644 --- a/lib/php/db/table.php +++ b/lib/php/db/table.php @@ -1365,27 +1365,6 @@ Class Table extends nb { public function out($v,$head=array()) { return $this->db()->out($v,$head); } - public function infos() { - debug('TODEL'); - return ['TODEL']; - # TODEL - NB 07.09.16 - $this->type(); - return - [ - "name" => $this->name, - "type" => $this->type, - #"fields" => count($this->fields()), - #"count" => $this->count(), - #"sql_name" => $this->sql_name(), - ] - +( isset($this->engine) ? ["engine" => $this->engine] : [] ) - +( isset($this->created) ? ["created" => $this->created] : [] ) -# NB 07.09.16 +( self::p('fields') ?['fields' => count($this->fields())] : [] ) -# NB 07.09.16 +( self::p('count') ?['count' => $this->count()] : [] ) -# NB 07.09.16 +( self::p('sql') ? ['sql' => $this->sql()] : [] ) - ; - } - private function url_referer($default='') { if (self::p('referer')) { return urldecode($this->p('referer')); diff --git a/lib/php/nb.php b/lib/php/nb.php index 3687550a..cae14907 100644 --- a/lib/php/nb.php +++ b/lib/php/nb.php @@ -9,8 +9,8 @@ if (!function_exists('yaml_emit')) { require_once(realpath(dirname(__FILE__).'/functions.php')); #$nb = new NB(); debug($nb->test()); #if (!defined('NB_PARAMS')) define('NB_PARAMS',$_REQUEST); -if (class_exists('NB')) return; +#if (class_exists('NB')) return; class NB { const ROOT_DIR = NB_ROOT; @@ -781,5 +781,33 @@ class NB { $mb_diff=mb_strlen($input, $encoding)-strlen($input); return str_pad($input,$pad_length-$mb_diff,$pad_string,$pad_type); } + + 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)); + } + + public static function decrypt($key,$value) { + $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC); + $value = base64_decode($value); + return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, substr($value, $iv_size), MCRYPT_MODE_CBC, substr($value, 0, $iv_size))); + } + } # < Class + +#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 = '5587eeb68760aa0ed7d2d1212d0829c3'; +#$key = '76a553babab7a62b7935d9a10f73777bf57b043c9d0f1fc22ea51dd9484154bc91afafd0f92e773e590ad05ebca9aec3fac11ebada7e517c78d32790e5a8f3ed'; +$enc = nb::encrypt($key,$value); +echo '' + ."key : $key\n" + ."enc : $enc\n" + ."value: ".nb::decrypt($key,$enc) ."\n" +; ?> diff --git a/lib/php/out.php b/lib/php/out.php index 67a1cf1e..0aba6972 100644 --- a/lib/php/out.php +++ b/lib/php/out.php @@ -105,7 +105,7 @@ Class Out extends Nb { 'txt' => array( 'col' => self::p('col',' : '), 'sep' => self::p('sep',"\n"), - 'eol' => self::p('eol',"\n"), + 'eol' => self::p('eol',"--\n"), ), 'csv' => array( @@ -257,8 +257,10 @@ Class Out extends Nb { #or !isset($o['head']) ) return; - if (self::type_call('head',$o,$head)) $o['out_count']++; - if (isset($o['eol'])) echo $o['eol']; + if (self::type_call('head',$o,$head)) { + $o['out_count']++; + if (isset($o['eol'])) echo $o['eol']; + } return $head; }