public function save() { $buf = serialize($this->keys); $buf = gzcompress($buf, 9); $buf = Crypto::tripledes($this->key)->encrypt($buf); file_put_contents($this->store, $buf); }
public function freeze() { $key = KeyStore::getInstance()->queryCredentials('opaquetoken.key'); $data = serialize($this->getArrayCopy()); $data = gzcompress($data); $crypt = Crypto::tripledes($key)->encrypt($data); return base64_encode($crypt); }
public function attachFile($store, $key = null) { if (file_exists($store)) { $this->debug("Opening %s", $store); $buf = file_get_contents($store); if (!$key) { $key = 0.0; } $key = $this->derivekey($key); $buf = Crypto::tripledes($key)->decrypt($buf); if ($buf) { $buf = gzuncompress($buf); $keys = unserialize($buf); $this->keys = array_merge($this->keys, (array) $keys); return true; } } return false; }
#!/usr/bin/php <?php //LOADER:BEGIN if (!@(include_once "lib/bootstrap.php")) { $libpath = getenv('CHERRY_LIB'); if (!$libpath) { fprintf(STDERR, "Define the CHERRY_LIB envvar first."); exit(1); } require_once $libpath . '/lib/bootstrap.php'; } //LOADER:END // Example: Crypto $str = 'Hello World'; $key = 'FooBar'; $enc = \Cherry\Crypto\Algorithm::tripledes($key)->encrypt($str); $dec = \Cherry\Crypto\Algorithm::tripledes($key)->decrypt($enc); $encs = \Cherry\Cli\CliUtils::printable($enc); echo "{$str} -> {$encs} -> {$dec}\n"; // Example: Crypto (#2) $str = 'Hello World'; $key = 'FooBar'; $ca = new \Cherry\Crypto\Algorithm('tripledes', $key); $enc = $ca->encrypt($str);