/** * @preserveGlobalState disabled * @runInSeparateProcess */ public function test_plaintext() { $this->assertFalse(Hm_Crypt::plaintext('asdf', 'testkey')); $this->assertFalse(Hm_Crypt::plaintext(base64_encode(str_repeat('a', 201)), 'testkey')); $cipher = Hm_Crypt::ciphertext('test', 'testkey'); $plain = rtrim(Hm_Crypt::plaintext($cipher, 'testkey'), ""); $this->assertEquals('test', $plain); }
/** * Encrypt session data * @param array $data session data to encrypt * @return string encrypted session data */ public function ciphertext($data) { return Hm_Crypt::ciphertext(serialize($data), $this->enc_key); }
public function process() { if (array_key_exists('upload_file', $this->request->files)) { $file = $this->request->files['upload_file']; if (is_readable($file['tmp_name'])) { $content = file_get_contents($file['tmp_name']); if ($content) { $content = Hm_Crypt::ciphertext($content, Hm_Request_Key::generate()); $filename = hash('sha512', $content); $filepath = $this->config->get('attachment_dir'); if ($filepath) { $filepath = rtrim($filepath, '/'); if (@file_put_contents($filepath . '/' . $filename, $content)) { $file['filename'] = $filepath . '/' . $filename; $file['basename'] = $filename; $files = $this->session->get('uploaded_files', array()); $this->session->set('uploaded_files', array_merge($files, array($file))); $this->out('upload_file_details', $file); } else { Hm_Msgs::add('ERRAn error occurred saving the uploaded file.'); } } else { Hm_Msgs::add('ERRNo directory configured for uploaded files.'); } } else { Hm_Msgs::add('ERRAn error occurred reading the uploaded file.'); } } else { Hm_Msgs::add('ERRAn error occurred reading the uploaded file.'); } } }
/** * Save user settings to the DB * @param string $username username * @param string $key encryption key * @return void */ public function save($username, $key) { $config = Hm_Crypt::ciphertext(serialize($this->config), $key); if (!$this->connect()) { return false; } $sql = $this->dbh->prepare("update hm_user_settings set settings=? where username=?"); if ($sql->execute(array($config, $username)) && $sql->rowCount() == 1) { Hm_Debug::add(sprintf("Saved user data to DB for %s", $username)); return true; } $sql = $this->dbh->prepare("insert into hm_user_settings values(?,?)"); if ($sql->execute(array($username, $config))) { return true; } return false; }