Beispiel #1
0
 /**
  * @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);
 }
Beispiel #2
0
 function process_attachments()
 {
     $res = '';
     foreach ($this->attachments as $file) {
         $content = Hm_Crypt::plaintext(@file_get_contents($file['filename']), Hm_Request_Key::generate());
         if ($content) {
             $content = chunk_split(base64_encode($content));
             $res .= sprintf("\r\n--%s\r\nContent-Type: %s; name=\"%s\"\r\nContent-Description: %s\r\n" . "Content-Disposition: attachment; filename=\"%s\"\r\nContent-Transfer-Encoding: base64\r\n\r\n%s", $this->boundary, $file['type'], $file['name'], $file['name'], $file['name'], $content);
         }
     }
     return $res;
 }
Beispiel #3
0
 /**
  * Decrypt session data
  * @param array $data encrypted session data
  * @return array decrpted session data
  */
 public function plaintext($data)
 {
     return @unserialize(Hm_Crypt::plaintext($data, $this->enc_key));
 }
Beispiel #4
0
 /**
  * Load the user settings from the DB
  * @param string $username username
  * @param string $key encryption key
  * @return void
  */
 public function load($username, $key)
 {
     if ($this->connect()) {
         $sql = $this->dbh->prepare("select * from hm_user_settings where username=?");
         if ($sql->execute(array($username))) {
             $data = $sql->fetch();
             if (!$data || !array_key_exists('settings', $data)) {
                 $sql = $this->dbh->prepare("insert into hm_user_settings values(?,?)");
                 if ($sql->execute(array($username, ''))) {
                     Hm_Debug::add(sprintf("created new row in hm_user_settings for %s", $username));
                     $this->config = array();
                 }
             } else {
                 $data = @unserialize(Hm_Crypt::plaintext($data['settings'], $key));
                 if (is_array($data)) {
                     $this->config = array_merge($this->config, $data);
                     $this->set_tz();
                 }
             }
         }
     }
 }