コード例 #1
0
ファイル: Update20150116130622.php プロジェクト: scalr/scalr
 /**
  * Reencrypts specified fields
  *
  * @param string     $table  Table name
  * @param string[]   $fields Fields name
  * @param string     $where  WHERE statement for SELECT query
  * @param string[]   $pks    Primary keys names
  * @param CryptoTool $source
  *
  * @return int Returns number of affected rows
  */
 public function recrypt($table, $fields, $where = '', $pks = ['id'], CryptoTool $source = null)
 {
     if ($source === null) {
         $source = $this->source;
     }
     $this->console->out("Reencrypting table '{$table}' fields:\n\t" . implode("\n\t", $fields));
     $names = '`' . implode('`, `', array_merge($pks, $fields)) . '`';
     $data = $this->db->Execute("SELECT {$names} FROM `{$table}` {$where} FOR UPDATE;");
     $params = '`' . implode('` = ?, `', $fields) . '` = ?';
     $where = '`' . implode('` = ? AND `', $pks) . '` = ?';
     $stmt = $this->db->Prepare("UPDATE `{$table}` SET {$params} WHERE {$where};");
     $affected = 0;
     foreach ($data as $entry) {
         $in = [];
         foreach ($fields as $field) {
             $in[] = $this->target->encrypt($source->_decrypt($entry[$field]));
         }
         foreach ($pks as $pk) {
             $in[] = $entry[$pk];
         }
         $this->db->Execute($stmt, $in);
         $affected += $this->db->Affected_Rows();
     }
     $this->console->out("Updated {$affected} rows!\n");
     return $affected;
 }
コード例 #2
0
ファイル: CryptoToolTest.php プロジェクト: mheydt/scalr
 /**
  * @test
  * @dataProvider providerTestCrypto
  */
 public function testDecryptoSzr($string)
 {
     if (self::$testSzr) {
         $key = base64_encode(self::$cryptoSzr->getCryptoKey());
         $str = escapeshellarg(self::$cryptoSzr->encrypt($string));
         exec('python ' . __DIR__ . "/CryptoToolSzr.py decrypt {$str} {$key}", $result);
         $this->assertEquals($string, $result[0]);
     } else {
         $this->markTestSkipped();
     }
 }