| @@ 64-83 (lines=20) @@ | ||
| 61 | * @param string $passphrase The passphrase for the key. |
|
| 62 | * @return void |
|
| 63 | */ |
|
| 64 | public function addDecryptKey($key, $passphrase) |
|
| 65 | { |
|
| 66 | $keyInfo = $this->_gpg->keyinfo($key); |
|
| 67 | if (count($keyInfo) !== 1) { |
|
| 68 | throw new Exception('Could not find a unique key'); |
|
| 69 | } |
|
| 70 | ||
| 71 | if (!$keyInfo[0]['can_sign']) { |
|
| 72 | throw new Exception('Key not a valid decryption key'); |
|
| 73 | } |
|
| 74 | ||
| 75 | $isDecryptionKey = function($subKey) { |
|
| 76 | return $subKey['can_sign']; |
|
| 77 | }; |
|
| 78 | ||
| 79 | $decryptionKeys = array_values(array_filter($keyInfo[0]['subkeys'], $isDecryptionKey)); |
|
| 80 | if (!$this->_gpg->adddecryptkey($decryptionKeys[0]['fingerprint'], $passphrase)) { |
|
| 81 | throw new Exception('Failed to add the decryption key'); |
|
| 82 | } |
|
| 83 | } |
|
| 84 | ||
| 85 | /** |
|
| 86 | * Add the given encryption key. |
|
| @@ 92-111 (lines=20) @@ | ||
| 89 | * @param string $key The uid or fingerprint of the key to add. |
|
| 90 | * @return void |
|
| 91 | */ |
|
| 92 | public function addEncryptKey($key) |
|
| 93 | { |
|
| 94 | $keyInfo = $this->_gpg->keyinfo($key); |
|
| 95 | if (count($keyInfo) !== 1) { |
|
| 96 | throw new Exception('Could not find a unique key'); |
|
| 97 | } |
|
| 98 | ||
| 99 | if (!$keyInfo[0]['can_encrypt']) { |
|
| 100 | throw new Exception('Key not a valid encryption key'); |
|
| 101 | } |
|
| 102 | ||
| 103 | $isEncryptionKey = function($subKey) { |
|
| 104 | return $subKey['can_encrypt']; |
|
| 105 | }; |
|
| 106 | ||
| 107 | $encryptionKeys = array_values(array_filter($keyInfo[0]['subkeys'], $isEncryptionKey)); |
|
| 108 | if (!$this->_gpg->addencryptkey($encryptionKeys[0]['fingerprint'])) { |
|
| 109 | throw new Exception('Failed to add the encryption key'); |
|
| 110 | } |
|
| 111 | } |
|
| 112 | ||
| 113 | /** |
|
| 114 | * Save the passwords to the password file. |
|