| | |
| | | |
| | | // Create Crypt_GPG object |
| | | try { |
| | | $this->gpg = new Crypt_GPG(array( |
| | | $this->gpg = new Crypt_GPG(array( |
| | | 'homedir' => $this->homedir, |
| | | // 'debug' => true, |
| | | )); |
| | |
| | | function encrypt($text, $keys) |
| | | { |
| | | /* |
| | | foreach ($keys as $key) { |
| | | $this->gpg->addEncryptKey($key); |
| | | } |
| | | $enc = $this->gpg->encrypt($text); |
| | | return $enc; |
| | | foreach ($keys as $key) { |
| | | $this->gpg->addEncryptKey($key); |
| | | } |
| | | $enc = $this->gpg->encrypt($text); |
| | | return $enc; |
| | | */ |
| | | } |
| | | |
| | | function decrypt($text, $key, $passwd) |
| | | { |
| | | // $this->gpg->addDecryptKey($key, $passwd); |
| | | // $this->gpg->addDecryptKey($key, $passwd); |
| | | try { |
| | | $dec = $this->gpg->decrypt($text); |
| | | return $dec; |
| | | $dec = $this->gpg->decrypt($text); |
| | | return $dec; |
| | | } |
| | | catch (Exception $e) { |
| | | return $this->get_error_from_exception($e); |
| | |
| | | function sign($text, $key, $passwd) |
| | | { |
| | | /* |
| | | $this->gpg->addSignKey($key, $passwd); |
| | | $signed = $this->gpg->sign($text, Crypt_GPG::SIGN_MODE_DETACHED); |
| | | return $signed; |
| | | $this->gpg->addSignKey($key, $passwd); |
| | | $signed = $this->gpg->sign($text, Crypt_GPG::SIGN_MODE_DETACHED); |
| | | return $signed; |
| | | */ |
| | | } |
| | | |
| | | function verify($text, $signature) |
| | | { |
| | | try { |
| | | $verified = $this->gpg->verify($text, $signature); |
| | | return $this->parse_signature($verified[0]); |
| | | $verified = $this->gpg->verify($text, $signature); |
| | | return $this->parse_signature($verified[0]); |
| | | } |
| | | catch (Exception $e) { |
| | | return $this->get_error_from_exception($e); |
| | |
| | | return $this->get_error_from_exception($e); |
| | | } |
| | | } |
| | | |
| | | |
| | | public function list_keys($pattern='') |
| | | { |
| | | try { |
| | | $keys = $this->gpg->getKeys($pattern); |
| | | $keys = $this->gpg->getKeys($pattern); |
| | | $result = array(); |
| | | //print_r($keys); |
| | | foreach ($keys as $idx => $key) { |
| | |
| | | unset($keys[$idx]); |
| | | } |
| | | //print_r($result); |
| | | return $result; |
| | | return $result; |
| | | } |
| | | catch (Exception $e) { |
| | | return $this->get_error_from_exception($e); |
| | | } |
| | | } |
| | | |
| | | |
| | | public function get_key($keyid) |
| | | { |
| | | $list = $this->list_keys($keyid); |
| | |
| | | if (is_array($list)) |
| | | return array_shift($list); |
| | | |
| | | // error |
| | | // error |
| | | return $list; |
| | | } |
| | | |
| | |
| | | public function del_key($keyid) |
| | | { |
| | | // $this->get_key($keyid); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | public function del_privkey($keyid) |
| | | { |
| | | try { |
| | | $this->gpg->deletePrivateKey($keyid); |
| | | $this->gpg->deletePrivateKey($keyid); |
| | | return true; |
| | | } |
| | | catch (Exception $e) { |
| | |
| | | public function del_pubkey($keyid) |
| | | { |
| | | try { |
| | | $this->gpg->deletePublicKey($keyid); |
| | | $this->gpg->deletePublicKey($keyid); |
| | | return true; |
| | | } |
| | | catch (Exception $e) { |
| | | return $this->get_error_from_exception($e); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Converts Crypt_GPG exception into Enigma's error object |
| | | * |
| | |
| | | |
| | | $ekey->users[$idx] = $id; |
| | | } |
| | | |
| | | |
| | | $ekey->name = trim($ekey->users[0]->name . ' <' . $ekey->users[0]->email . '>'); |
| | | |
| | | foreach ($key->getSubKeys() as $idx => $subkey) { |
| | |
| | | |
| | | $ekey->subkeys[$idx] = $skey; |
| | | }; |
| | | |
| | | |
| | | $ekey->id = $ekey->subkeys[0]->id; |
| | | |
| | | |
| | | return $ekey; |
| | | } |
| | | } |