Rev 846 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
827 | daniel-mar | 1 | <?php |
2 | |||
3 | /** |
||
4 | * Password Protected Trait for Private Keys |
||
5 | * |
||
6 | * PHP version 5 |
||
7 | * |
||
874 | daniel-mar | 8 | * @category Crypt |
9 | * @package Common |
||
827 | daniel-mar | 10 | * @author Jim Wigginton <terrafrost@php.net> |
11 | * @copyright 2015 Jim Wigginton |
||
12 | * @license http://www.opensource.org/licenses/mit-license.html MIT License |
||
13 | * @link http://phpseclib.sourceforge.net |
||
14 | */ |
||
15 | |||
16 | namespace phpseclib3\Crypt\Common\Traits; |
||
17 | |||
18 | /** |
||
19 | * Password Protected Trait for Private Keys |
||
20 | * |
||
874 | daniel-mar | 21 | * @package Common |
827 | daniel-mar | 22 | * @author Jim Wigginton <terrafrost@php.net> |
874 | daniel-mar | 23 | * @access public |
827 | daniel-mar | 24 | */ |
25 | trait PasswordProtected |
||
26 | { |
||
27 | /** |
||
28 | * Password |
||
29 | * |
||
30 | * @var string|bool |
||
31 | */ |
||
32 | private $password = false; |
||
33 | |||
34 | /** |
||
35 | * Sets the password |
||
36 | * |
||
37 | * Private keys can be encrypted with a password. To unset the password, pass in the empty string or false. |
||
38 | * Or rather, pass in $password such that empty($password) && !is_string($password) is true. |
||
39 | * |
||
40 | * @see self::createKey() |
||
41 | * @see self::load() |
||
874 | daniel-mar | 42 | * @access public |
827 | daniel-mar | 43 | * @param string|bool $password |
44 | */ |
||
45 | public function withPassword($password = false) |
||
46 | { |
||
47 | $new = clone $this; |
||
48 | $new->password = $password; |
||
49 | return $new; |
||
50 | } |
||
51 | } |