PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / 3.1.23.3
JetBackup – Backup, Restore & Migrate v3.1.23.3
3.1.23.3 3.1.22.4 3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / src / JetBackup / 3rdparty / phpseclib3 / Crypt / DSA / Formats / Keys / PKCS8.php
backup / src / JetBackup / 3rdparty / phpseclib3 / Crypt / DSA / Formats / Keys Last commit date
.htaccess 1 year ago OpenSSH.php 1 year ago PKCS1.php 1 year ago PKCS8.php 1 year ago PuTTY.php 1 year ago Raw.php 1 year ago XML.php 1 year ago index.html 1 year ago web.config 1 year ago
PKCS8.php
134 lines
1 <?php
2
3 /**
4 * PKCS#8 Formatted DSA Key Handler
5 *
6 * PHP version 5
7 *
8 * Processes keys with the following headers:
9 *
10 * -----BEGIN ENCRYPTED PRIVATE KEY-----
11 * -----BEGIN PRIVATE KEY-----
12 * -----BEGIN PUBLIC KEY-----
13 *
14 * Analogous to ssh-keygen's pkcs8 format (as specified by -m). Although PKCS8
15 * is specific to private keys it's basically creating a DER-encoded wrapper
16 * for keys. This just extends that same concept to public keys (much like ssh-keygen)
17 *
18 * @author Jim Wigginton <terrafrost@php.net>
19 * @copyright 2015 Jim Wigginton
20 * @license http://www.opensource.org/licenses/mit-license.html MIT License
21 * @link http://phpseclib.sourceforge.net
22 */
23
24 declare(strict_types=1);
25
26 namespace phpseclib3\Crypt\DSA\Formats\Keys;
27
28 use phpseclib3\Crypt\Common\Formats\Keys\PKCS8 as Progenitor;
29 use phpseclib3\Exception\RuntimeException;
30 use phpseclib3\File\ASN1;
31 use phpseclib3\File\ASN1\Maps;
32 use phpseclib3\Math\BigInteger;
33
34 /**
35 * PKCS#8 Formatted DSA Key Handler
36 *
37 * @author Jim Wigginton <terrafrost@php.net>
38 */
39 abstract class PKCS8 extends Progenitor
40 {
41 /**
42 * OID Name
43 *
44 * @var string
45 */
46 public const OID_NAME = 'id-dsa';
47
48 /**
49 * OID Value
50 *
51 * @var string
52 */
53 public const OID_VALUE = '1.2.840.10040.4.1';
54
55 /**
56 * Child OIDs loaded
57 *
58 * @var bool
59 */
60 protected static $childOIDsLoaded = false;
61
62 /**
63 * Break a public or private key down into its constituent components
64 *
65 * @param string|array $key
66 */
67 public static function load($key, ?string $password = null): array
68 {
69 $key = parent::load($key, $password);
70
71 $type = isset($key['privateKey']) ? 'privateKey' : 'publicKey';
72
73 $decoded = ASN1::decodeBER($key[$type . 'Algorithm']['parameters']->element);
74 if (!$decoded) {
75 throw new RuntimeException('Unable to decode BER of parameters');
76 }
77 $components = ASN1::asn1map($decoded[0], Maps\DSAParams::MAP);
78 if (!is_array($components)) {
79 throw new RuntimeException('Unable to perform ASN1 mapping on parameters');
80 }
81
82 $decoded = ASN1::decodeBER($key[$type]);
83 if (empty($decoded)) {
84 throw new RuntimeException('Unable to decode BER');
85 }
86
87 $var = $type == 'privateKey' ? 'x' : 'y';
88 $components[$var] = ASN1::asn1map($decoded[0], Maps\DSAPublicKey::MAP);
89 if (!$components[$var] instanceof BigInteger) {
90 throw new RuntimeException('Unable to perform ASN1 mapping');
91 }
92
93 if (isset($key['meta'])) {
94 $components['meta'] = $key['meta'];
95 }
96
97 return $components;
98 }
99
100 /**
101 * Convert a private key to the appropriate format.
102 */
103 public static function savePrivateKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y, BigInteger $x, ?string $password = null, array $options = []): string
104 {
105 $params = [
106 'p' => $p,
107 'q' => $q,
108 'g' => $g,
109 ];
110 $params = ASN1::encodeDER($params, Maps\DSAParams::MAP);
111 $params = new ASN1\Element($params);
112 $key = ASN1::encodeDER($x, Maps\DSAPublicKey::MAP);
113 return self::wrapPrivateKey($key, [], $params, $password, null, '', $options);
114 }
115
116 /**
117 * Convert a public key to the appropriate format
118 *
119 * @param array $options optional
120 */
121 public static function savePublicKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y, array $options = []): string
122 {
123 $params = [
124 'p' => $p,
125 'q' => $q,
126 'g' => $g,
127 ];
128 $params = ASN1::encodeDER($params, Maps\DSAParams::MAP);
129 $params = new ASN1\Element($params);
130 $key = ASN1::encodeDER($y, Maps\DSAPublicKey::MAP);
131 return self::wrapPublicKey($key, $params);
132 }
133 }
134