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 / PKCS1.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
PKCS1.php
128 lines
1 <?php
2
3 /**
4 * PKCS#1 Formatted DSA Key Handler
5 *
6 * PHP version 5
7 *
8 * Used by File/X509.php
9 *
10 * Processes keys with the following headers:
11 *
12 * -----BEGIN DSA PRIVATE KEY-----
13 * -----BEGIN DSA PUBLIC KEY-----
14 * -----BEGIN DSA PARAMETERS-----
15 *
16 * Analogous to ssh-keygen's pem format (as specified by -m)
17 *
18 * Also, technically, PKCS1 decribes RSA but I am not aware of a formal specification for DSA.
19 * The DSA private key format seems to have been adapted from the RSA private key format so
20 * we're just re-using that as the name.
21 *
22 * @author Jim Wigginton <terrafrost@php.net>
23 * @copyright 2015 Jim Wigginton
24 * @license http://www.opensource.org/licenses/mit-license.html MIT License
25 * @link http://phpseclib.sourceforge.net
26 */
27
28 declare(strict_types=1);
29
30 namespace phpseclib3\Crypt\DSA\Formats\Keys;
31
32 use phpseclib3\Common\Functions\Strings;
33 use phpseclib3\Crypt\Common\Formats\Keys\PKCS1 as Progenitor;
34 use phpseclib3\Exception\RuntimeException;
35 use phpseclib3\File\ASN1;
36 use phpseclib3\File\ASN1\Maps;
37 use phpseclib3\Math\BigInteger;
38
39 /**
40 * PKCS#1 Formatted DSA Key Handler
41 *
42 * @author Jim Wigginton <terrafrost@php.net>
43 */
44 abstract class PKCS1 extends Progenitor
45 {
46 /**
47 * Break a public or private key down into its constituent components
48 *
49 * @param string|array $key
50 */
51 public static function load($key, ?string $password = null): array
52 {
53 $key = parent::load($key, $password);
54
55 $decoded = ASN1::decodeBER($key);
56 if (!$decoded) {
57 throw new RuntimeException('Unable to decode BER');
58 }
59
60 $key = ASN1::asn1map($decoded[0], Maps\DSAParams::MAP);
61 if (is_array($key)) {
62 return $key;
63 }
64
65 $key = ASN1::asn1map($decoded[0], Maps\DSAPrivateKey::MAP);
66 if (is_array($key)) {
67 return $key;
68 }
69
70 $key = ASN1::asn1map($decoded[0], Maps\DSAPublicKey::MAP);
71 if (is_array($key)) {
72 return $key;
73 }
74
75 throw new RuntimeException('Unable to perform ASN1 mapping');
76 }
77
78 /**
79 * Convert DSA parameters to the appropriate format
80 */
81 public static function saveParameters(BigInteger $p, BigInteger $q, BigInteger $g): string
82 {
83 $key = [
84 'p' => $p,
85 'q' => $q,
86 'g' => $g,
87 ];
88
89 $key = ASN1::encodeDER($key, Maps\DSAParams::MAP);
90
91 return "-----BEGIN DSA PARAMETERS-----\r\n" .
92 chunk_split(Strings::base64_encode($key), 64) .
93 "-----END DSA PARAMETERS-----\r\n";
94 }
95
96 /**
97 * Convert a private key to the appropriate format.
98 *
99 * @param string $password optional
100 * @param array $options optional
101 */
102 public static function savePrivateKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y, BigInteger $x, string $password = '', array $options = []): string
103 {
104 $key = [
105 'version' => 0,
106 'p' => $p,
107 'q' => $q,
108 'g' => $g,
109 'y' => $y,
110 'x' => $x,
111 ];
112
113 $key = ASN1::encodeDER($key, Maps\DSAPrivateKey::MAP);
114
115 return self::wrapPrivateKey($key, 'DSA', $password, $options);
116 }
117
118 /**
119 * Convert a public key to the appropriate format
120 */
121 public static function savePublicKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y): string
122 {
123 $key = ASN1::encodeDER($y, Maps\DSAPublicKey::MAP);
124
125 return self::wrapPublicKey($key, 'DSA');
126 }
127 }
128