]> git.nbdom.net Git - nb.git/commitdiff
encrypt, fix text eol
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 31 Oct 2016 02:09:50 +0000 (02:09 +0000)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Mon, 31 Oct 2016 02:09:50 +0000 (02:09 +0000)
lib/php/db.php
lib/php/db/table.php
lib/php/nb.php
lib/php/out.php

index 8d74357fdd32e20db6eb501e6ff65995777ccc9b..173bec367df60d06dc9588caddbf2832706ff1e5 100644 (file)
@@ -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());
 
   }
index 8b899489fa17eb77a7ffe36dcde2a0af5d1a62e4..9ed3b6c1a9376ee464a518c0d757173bcd120e64 100644 (file)
@@ -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'));
index 3687550a46eb8022395d6cf70388734a3cb22851..cae14907936fd89429950e25786c84ac7d102ddc 100644 (file)
@@ -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"
+;
 ?>
index 67a1cf1e4533c8f1a35a5f8697b1e00262c0ad5d..0aba69720ddc2af4ec3a6b8f1f2b401ceab7aab7 100644 (file)
@@ -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;
 
   }