mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-11-14 09:24:07 +00:00
Merge branch '3.0'
This commit is contained in:
commit
3c73d61e7e
@ -15,6 +15,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpseclib3\Common\Functions;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use ParagonIE\ConstantTime\Base64UrlSafe;
|
||||
use phpseclib3\Math\BigInteger;
|
||||
use phpseclib3\Math\Common\FiniteField;
|
||||
|
||||
@ -385,4 +387,63 @@ abstract class Strings
|
||||
{
|
||||
return is_string($var) || (is_object($var) && method_exists($var, '__toString'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Constant Time Base64-decoding
|
||||
*
|
||||
* ParagoneIE\ConstantTime doesn't use libsodium if it's available so we'll do so
|
||||
* ourselves. see https://github.com/paragonie/constant_time_encoding/issues/39
|
||||
*
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
public static function base64_decode($data)
|
||||
{
|
||||
return function_exists('sodium_base642bin') ?
|
||||
sodium_base642bin($data, SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING, '=') :
|
||||
Base64::decode($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constant Time Base64-decoding (URL safe)
|
||||
*
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
public static function base64url_decode($data)
|
||||
{
|
||||
// return self::base64_decode(str_replace(['-', '_'], ['+', '/'], $data));
|
||||
|
||||
return function_exists('sodium_base642bin') ?
|
||||
sodium_base642bin($data, SODIUM_BASE64_VARIANT_URLSAFE_NO_PADDING, '=') :
|
||||
Base64UrlSafe::decode($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constant Time Base64-encoding
|
||||
*
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
public static function base64_encode($data)
|
||||
{
|
||||
return function_exists('sodium_bin2base64') ?
|
||||
sodium_bin2base64($data, SODIUM_BASE64_VARIANT_ORIGINAL) :
|
||||
Base64::encode($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constant Time Base64-encoding (URL safe)
|
||||
*
|
||||
* @param string $data
|
||||
* @return string
|
||||
*/
|
||||
public static function base64url_encode($data)
|
||||
{
|
||||
// return self::base64_encode(str_replace(['+', '/'], ['-', '_'], $data));
|
||||
|
||||
return function_exists('sodium_bin2base64') ?
|
||||
sodium_bin2base64($data, SODIUM_BASE64_VARIANT_URLSAFE) :
|
||||
Base64::encode($data);
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpseclib3\Crypt\Common\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Crypt\AES;
|
||||
use phpseclib3\Crypt\Random;
|
||||
@ -70,7 +69,7 @@ abstract class OpenSSH
|
||||
|
||||
if (strpos($key, 'BEGIN OPENSSH PRIVATE KEY') !== false) {
|
||||
$key = preg_replace('#(?:^-.*?-[\r\n]*$)|\s#ms', '', $key);
|
||||
$key = Base64::decode($key);
|
||||
$key = Strings::base64_decode($key);
|
||||
$magic = Strings::shift($key, 15);
|
||||
if ($magic != "openssh-key-v1\0") {
|
||||
throw new \RuntimeException('Expected openssh-key-v1');
|
||||
@ -207,7 +206,7 @@ abstract class OpenSSH
|
||||
$key = "openssh-key-v1\0$key";
|
||||
|
||||
return "-----BEGIN OPENSSH PRIVATE KEY-----\n" .
|
||||
chunk_split(Base64::encode($key), 70, "\n") .
|
||||
chunk_split(Strings::base64_encode($key), 70, "\n") .
|
||||
"-----END OPENSSH PRIVATE KEY-----\n";
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpseclib3\Crypt\Common\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use ParagonIE\ConstantTime\Hex;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Crypt\AES;
|
||||
@ -165,7 +164,7 @@ abstract class PKCS1 extends PKCS
|
||||
{
|
||||
if (empty($password) || !is_string($password)) {
|
||||
return "-----BEGIN $type PRIVATE KEY-----\r\n" .
|
||||
chunk_split(Base64::encode($key), 64) .
|
||||
chunk_split(Strings::base64_encode($key), 64) .
|
||||
"-----END $type PRIVATE KEY-----";
|
||||
}
|
||||
|
||||
@ -180,7 +179,7 @@ abstract class PKCS1 extends PKCS
|
||||
"Proc-Type: 4,ENCRYPTED\r\n" .
|
||||
"DEK-Info: " . $encryptionAlgorithm . ",$iv\r\n" .
|
||||
"\r\n" .
|
||||
chunk_split(Base64::encode($cipher->encrypt($key)), 64) .
|
||||
chunk_split(Strings::base64_encode($cipher->encrypt($key)), 64) .
|
||||
"-----END $type PRIVATE KEY-----";
|
||||
}
|
||||
|
||||
@ -190,7 +189,7 @@ abstract class PKCS1 extends PKCS
|
||||
protected static function wrapPublicKey(string $key, string $type): string
|
||||
{
|
||||
return "-----BEGIN $type PUBLIC KEY-----\r\n" .
|
||||
chunk_split(Base64::encode($key), 64) .
|
||||
chunk_split(Strings::base64_encode($key), 64) .
|
||||
"-----END $type PUBLIC KEY-----";
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpseclib3\Crypt\Common\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Crypt\AES;
|
||||
use phpseclib3\Crypt\Common\SymmetricKey;
|
||||
@ -581,12 +580,12 @@ abstract class PKCS8 extends PKCS
|
||||
$key = ASN1::encodeDER($key, Maps\EncryptedPrivateKeyInfo::MAP);
|
||||
|
||||
return "-----BEGIN ENCRYPTED PRIVATE KEY-----\r\n" .
|
||||
chunk_split(Base64::encode($key), 64) .
|
||||
chunk_split(Strings::base64_encode($key), 64) .
|
||||
"-----END ENCRYPTED PRIVATE KEY-----";
|
||||
}
|
||||
|
||||
return "-----BEGIN PRIVATE KEY-----\r\n" .
|
||||
chunk_split(Base64::encode($key), 64) .
|
||||
chunk_split(Strings::base64_encode($key), 64) .
|
||||
"-----END PRIVATE KEY-----";
|
||||
}
|
||||
|
||||
@ -611,7 +610,7 @@ abstract class PKCS8 extends PKCS
|
||||
$key = ASN1::encodeDER($key, Maps\PublicKeyInfo::MAP);
|
||||
|
||||
return "-----BEGIN PUBLIC KEY-----\r\n" .
|
||||
chunk_split(Base64::encode($key), 64) .
|
||||
chunk_split(Strings::base64_encode($key), 64) .
|
||||
"-----END PUBLIC KEY-----";
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpseclib3\Crypt\Common\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use ParagonIE\ConstantTime\Hex;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Crypt\AES;
|
||||
@ -184,7 +183,7 @@ abstract class PuTTY
|
||||
$components['comment'] = trim(preg_replace('#Comment: (.+)#', '$1', $key[2]));
|
||||
|
||||
$publicLength = (int) trim(preg_replace('#Public-Lines: (\d+)#', '$1', $key[3]));
|
||||
$public = Base64::decode(implode('', array_map('trim', array_slice($key, 4, $publicLength))));
|
||||
$public = Strings::base64_decode(implode('', array_map('trim', array_slice($key, 4, $publicLength))));
|
||||
|
||||
$source = Strings::packSSH2('ssss', $type, $encryption, $components['comment'], $public);
|
||||
|
||||
@ -237,7 +236,7 @@ abstract class PuTTY
|
||||
}
|
||||
|
||||
$privateLength = (int) trim(preg_replace('#Private-Lines: (\d+)#', '$1', $key[$offset++]));
|
||||
$private = Base64::decode(implode('', array_map('trim', array_slice($key, $offset, $privateLength))));
|
||||
$private = Strings::base64_decode(implode('', array_map('trim', array_slice($key, $offset, $privateLength))));
|
||||
|
||||
if ($encryption != 'none') {
|
||||
$crypto->setKey($symkey);
|
||||
@ -280,7 +279,7 @@ abstract class PuTTY
|
||||
|
||||
$source = Strings::packSSH2('ssss', $type, $encryption, $comment, $public);
|
||||
|
||||
$public = Base64::encode($public);
|
||||
$public = Strings::base64_encode($public);
|
||||
$key .= "Public-Lines: " . ((strlen($public) + 63) >> 6) . "\r\n";
|
||||
$key .= chunk_split($public, 64);
|
||||
|
||||
@ -330,7 +329,7 @@ abstract class PuTTY
|
||||
$mac = $hash->hash($source);
|
||||
}
|
||||
|
||||
$private = Base64::encode($private);
|
||||
$private = Strings::base64_encode($private);
|
||||
$key .= 'Private-Lines: ' . ((strlen($private) + 63) >> 6) . "\r\n";
|
||||
$key .= chunk_split($private, 64);
|
||||
$key .= 'Private-MAC: ' . Hex::encode($hash->hash($source)) . "\r\n";
|
||||
@ -348,7 +347,7 @@ abstract class PuTTY
|
||||
$key = pack('Na*a*', strlen($type), $type, $key);
|
||||
$key = "---- BEGIN SSH2 PUBLIC KEY ----\r\n" .
|
||||
'Comment: "' . str_replace(['\\', '"'], ['\\\\', '\"'], self::$comment) . "\"\r\n" .
|
||||
chunk_split(Base64::encode($key), 64) .
|
||||
chunk_split(Strings::base64_encode($key), 64) .
|
||||
'---- END SSH2 PUBLIC KEY ----';
|
||||
return $key;
|
||||
}
|
||||
|
@ -29,11 +29,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpseclib3\Crypt\DSA\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib3\Crypt\Common\Formats\Keys\PKCS1 as Progenitor;
|
||||
use phpseclib3\File\ASN1;
|
||||
use phpseclib3\File\ASN1\Maps;
|
||||
use phpseclib3\Math\BigInteger;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
|
||||
/**
|
||||
* PKCS#1 Formatted DSA Key Handler
|
||||
@ -88,7 +88,7 @@ abstract class PKCS1 extends Progenitor
|
||||
$key = ASN1::encodeDER($key, Maps\DSAParams::MAP);
|
||||
|
||||
return "-----BEGIN DSA PARAMETERS-----\r\n" .
|
||||
chunk_split(Base64::encode($key), 64) .
|
||||
chunk_split(Strings::base64_encode($key), 64) .
|
||||
"-----END DSA PARAMETERS-----\r\n";
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpseclib3\Crypt\DSA\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Exception\BadConfigurationException;
|
||||
use phpseclib3\Math\BigInteger;
|
||||
@ -64,7 +63,7 @@ abstract class XML
|
||||
if (!$temp->length) {
|
||||
continue;
|
||||
}
|
||||
$value = new BigInteger(Base64::decode($temp->item(0)->nodeValue), 256);
|
||||
$value = new BigInteger(Strings::base64_decode($temp->item(0)->nodeValue), 256);
|
||||
switch ($key) {
|
||||
case 'p': // a prime modulus meeting the [DSS] requirements
|
||||
// Parameters P, Q, and G can be public and common to a group of users. They might be known
|
||||
@ -116,10 +115,10 @@ abstract class XML
|
||||
public static function savePublicKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y): string
|
||||
{
|
||||
return "<DSAKeyValue>\r\n" .
|
||||
' <P>' . Base64::encode($p->toBytes()) . "</P>\r\n" .
|
||||
' <Q>' . Base64::encode($q->toBytes()) . "</Q>\r\n" .
|
||||
' <G>' . Base64::encode($g->toBytes()) . "</G>\r\n" .
|
||||
' <Y>' . Base64::encode($y->toBytes()) . "</Y>\r\n" .
|
||||
' <P>' . Strings::base64_encode($p->toBytes()) . "</P>\r\n" .
|
||||
' <Q>' . Strings::base64_encode($q->toBytes()) . "</Q>\r\n" .
|
||||
' <G>' . Strings::base64_encode($g->toBytes()) . "</G>\r\n" .
|
||||
' <Y>' . Strings::base64_encode($y->toBytes()) . "</Y>\r\n" .
|
||||
'</DSAKeyValue>';
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpseclib3\Crypt\EC\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Crypt\Common\Formats\Keys\PKCS1 as Progenitor;
|
||||
use phpseclib3\Crypt\EC\BaseCurves\Base as BaseCurve;
|
||||
@ -155,7 +154,7 @@ abstract class PKCS1 extends Progenitor
|
||||
$key = self::encodeParameters($curve, false, $options);
|
||||
|
||||
return "-----BEGIN EC PARAMETERS-----\r\n" .
|
||||
chunk_split(Base64::encode($key), 64) .
|
||||
chunk_split(Strings::base64_encode($key), 64) .
|
||||
"-----END EC PARAMETERS-----\r\n";
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpseclib3\Crypt\EC\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Crypt\Common\Formats\Keys\PuTTY as Progenitor;
|
||||
use phpseclib3\Crypt\EC\BaseCurves\Base as BaseCurve;
|
||||
@ -66,7 +65,7 @@ abstract class PuTTY extends Progenitor
|
||||
|
||||
$private = $components['private'];
|
||||
|
||||
$temp = Base64::encode(Strings::packSSH2('s', $components['type']) . $components['public']);
|
||||
$temp = Strings::base64_encode(Strings::packSSH2('s', $components['type']) . $components['public']);
|
||||
$components = OpenSSH::load($components['type'] . ' ' . $temp . ' ' . $components['comment']);
|
||||
|
||||
if ($components['curve'] instanceof TwistedEdwardsCurve) {
|
||||
@ -95,7 +94,7 @@ abstract class PuTTY extends Progenitor
|
||||
|
||||
$public = explode(' ', OpenSSH::savePublicKey($curve, $publicKey));
|
||||
$name = $public[0];
|
||||
$public = Base64::decode($public[1]);
|
||||
$public = Strings::base64_decode($public[1]);
|
||||
[, $length] = unpack('N', Strings::shift($public, 4));
|
||||
Strings::shift($public, $length);
|
||||
|
||||
@ -124,7 +123,7 @@ abstract class PuTTY extends Progenitor
|
||||
{
|
||||
$public = explode(' ', OpenSSH::savePublicKey($curve, $publicKey));
|
||||
$type = $public[0];
|
||||
$public = Base64::decode($public[1]);
|
||||
$public = Strings::base64_decode($public[1]);
|
||||
[, $length] = unpack('N', Strings::shift($public, 4));
|
||||
Strings::shift($public, $length);
|
||||
|
||||
|
@ -20,7 +20,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpseclib3\Crypt\EC\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Crypt\EC\BaseCurves\Base as BaseCurve;
|
||||
use phpseclib3\Crypt\EC\BaseCurves\Montgomery as MontgomeryCurve;
|
||||
@ -158,7 +157,7 @@ abstract class XML
|
||||
*/
|
||||
private static function decodeValue(string $value): string
|
||||
{
|
||||
return Base64::decode(str_replace(["\r", "\n", ' ', "\t"], '', $value));
|
||||
return Strings::base64_decode(str_replace(["\r", "\n", ' ', "\t"], '', $value));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -386,7 +385,7 @@ abstract class XML
|
||||
|
||||
return '<' . $pre . 'ECDSAKeyValue xmlns' . $post . '="http://www.w3.org/2009/xmldsig11#">' . "\r\n" .
|
||||
self::encodeXMLParameters($curve, $pre, $options) . "\r\n" .
|
||||
'<' . $pre . 'PublicKey>' . Base64::encode($publicKey) . '</' . $pre . 'PublicKey>' . "\r\n" .
|
||||
'<' . $pre . 'PublicKey>' . Strings::base64_encode($publicKey) . '</' . $pre . 'PublicKey>' . "\r\n" .
|
||||
'</' . $pre . 'ECDSAKeyValue>';
|
||||
}
|
||||
|
||||
@ -449,7 +448,7 @@ abstract class XML
|
||||
switch ($temp['fieldID']['fieldType']) {
|
||||
case 'prime-field':
|
||||
$xml .= '<' . $pre . 'Prime>' . "\r\n" .
|
||||
'<' . $pre . 'P>' . Base64::encode($temp['fieldID']['parameters']->toBytes()) . '</' . $pre . 'P>' . "\r\n" .
|
||||
'<' . $pre . 'P>' . Strings::base64_encode($temp['fieldID']['parameters']->toBytes()) . '</' . $pre . 'P>' . "\r\n" .
|
||||
'</' . $pre . 'Prime>' . "\r\n" ;
|
||||
break;
|
||||
default:
|
||||
@ -457,11 +456,11 @@ abstract class XML
|
||||
}
|
||||
$xml .= '</' . $pre . 'FieldID>' . "\r\n" .
|
||||
'<' . $pre . 'Curve>' . "\r\n" .
|
||||
'<' . $pre . 'A>' . Base64::encode($temp['curve']['a']) . '</' . $pre . 'A>' . "\r\n" .
|
||||
'<' . $pre . 'B>' . Base64::encode($temp['curve']['b']) . '</' . $pre . 'B>' . "\r\n" .
|
||||
'<' . $pre . 'A>' . Strings::base64_encode($temp['curve']['a']) . '</' . $pre . 'A>' . "\r\n" .
|
||||
'<' . $pre . 'B>' . Strings::base64_encode($temp['curve']['b']) . '</' . $pre . 'B>' . "\r\n" .
|
||||
'</' . $pre . 'Curve>' . "\r\n" .
|
||||
'<' . $pre . 'Base>' . Base64::encode($temp['base']) . '</' . $pre . 'Base>' . "\r\n" .
|
||||
'<' . $pre . 'Order>' . Base64::encode($temp['order']) . '</' . $pre . 'Order>' . "\r\n" .
|
||||
'<' . $pre . 'Base>' . Strings::base64_encode($temp['base']) . '</' . $pre . 'Base>' . "\r\n" .
|
||||
'<' . $pre . 'Order>' . Strings::base64_encode($temp['order']) . '</' . $pre . 'Order>' . "\r\n" .
|
||||
'</' . $pre . 'ECParameters>';
|
||||
return $xml;
|
||||
}
|
||||
|
@ -19,7 +19,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpseclib3\Crypt\RSA\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Exception\UnsupportedFormatException;
|
||||
use phpseclib3\Math\BigInteger;
|
||||
@ -71,7 +70,7 @@ abstract class MSBLOB
|
||||
throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key));
|
||||
}
|
||||
|
||||
$key = Base64::decode($key);
|
||||
$key = Strings::base64_decode($key);
|
||||
|
||||
if (!is_string($key)) {
|
||||
throw new \UnexpectedValueException('Base64 decoding produced an error');
|
||||
@ -190,7 +189,7 @@ abstract class MSBLOB
|
||||
$key .= strrev($coefficients[2]->toBytes());
|
||||
$key .= strrev($d->toBytes());
|
||||
|
||||
return Base64::encode($key);
|
||||
return Strings::base64_encode($key);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -204,6 +203,6 @@ abstract class MSBLOB
|
||||
$key .= pack('VVa*', self::RSA1, 8 * strlen($n), $e);
|
||||
$key .= $n;
|
||||
|
||||
return Base64::encode($key);
|
||||
return Strings::base64_encode($key);
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpseclib3\Crypt\RSA\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Exception\BadConfigurationException;
|
||||
use phpseclib3\Exception\UnsupportedFormatException;
|
||||
@ -75,7 +74,7 @@ abstract class XML
|
||||
if (!$temp->length) {
|
||||
continue;
|
||||
}
|
||||
$value = new BigInteger(Base64::decode($temp->item(0)->nodeValue), 256);
|
||||
$value = new BigInteger(Strings::base64_decode($temp->item(0)->nodeValue), 256);
|
||||
switch ($key) {
|
||||
case 'modulus':
|
||||
$components['modulus'] = $value;
|
||||
@ -137,14 +136,14 @@ abstract class XML
|
||||
}
|
||||
|
||||
return "<RSAKeyPair>\r\n" .
|
||||
' <Modulus>' . Base64::encode($n->toBytes()) . "</Modulus>\r\n" .
|
||||
' <Exponent>' . Base64::encode($e->toBytes()) . "</Exponent>\r\n" .
|
||||
' <P>' . Base64::encode($primes[1]->toBytes()) . "</P>\r\n" .
|
||||
' <Q>' . Base64::encode($primes[2]->toBytes()) . "</Q>\r\n" .
|
||||
' <DP>' . Base64::encode($exponents[1]->toBytes()) . "</DP>\r\n" .
|
||||
' <DQ>' . Base64::encode($exponents[2]->toBytes()) . "</DQ>\r\n" .
|
||||
' <InverseQ>' . Base64::encode($coefficients[2]->toBytes()) . "</InverseQ>\r\n" .
|
||||
' <D>' . Base64::encode($d->toBytes()) . "</D>\r\n" .
|
||||
' <Modulus>' . Strings::base64_encode($n->toBytes()) . "</Modulus>\r\n" .
|
||||
' <Exponent>' . Strings::base64_encode($e->toBytes()) . "</Exponent>\r\n" .
|
||||
' <P>' . Strings::base64_encode($primes[1]->toBytes()) . "</P>\r\n" .
|
||||
' <Q>' . Strings::base64_encode($primes[2]->toBytes()) . "</Q>\r\n" .
|
||||
' <DP>' . Strings::base64_encode($exponents[1]->toBytes()) . "</DP>\r\n" .
|
||||
' <DQ>' . Strings::base64_encode($exponents[2]->toBytes()) . "</DQ>\r\n" .
|
||||
' <InverseQ>' . Strings::base64_encode($coefficients[2]->toBytes()) . "</InverseQ>\r\n" .
|
||||
' <D>' . Strings::base64_encode($d->toBytes()) . "</D>\r\n" .
|
||||
'</RSAKeyPair>';
|
||||
}
|
||||
|
||||
@ -154,8 +153,8 @@ abstract class XML
|
||||
public static function savePublicKey(BigInteger $n, BigInteger $e): string
|
||||
{
|
||||
return "<RSAKeyValue>\r\n" .
|
||||
' <Modulus>' . Base64::encode($n->toBytes()) . "</Modulus>\r\n" .
|
||||
' <Exponent>' . Base64::encode($e->toBytes()) . "</Exponent>\r\n" .
|
||||
' <Modulus>' . Strings::base64_encode($n->toBytes()) . "</Modulus>\r\n" .
|
||||
' <Exponent>' . Strings::base64_encode($e->toBytes()) . "</Exponent>\r\n" .
|
||||
'</RSAKeyValue>';
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ declare(strict_types=1);
|
||||
namespace phpseclib3\File;
|
||||
|
||||
use DateTime;
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\File\ASN1\Element;
|
||||
use phpseclib3\Math\BigInteger;
|
||||
@ -1432,7 +1431,7 @@ abstract class ASN1
|
||||
$temp = str_replace(["\r", "\n", ' '], '', $temp);
|
||||
// remove the -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- stuff
|
||||
$temp = preg_replace('#^-+[^-]+-+|-+[^-]+-+$#', '', $temp);
|
||||
$temp = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $temp) ? Base64::decode($temp) : false;
|
||||
$temp = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $temp) ? Strings::base64_decode($temp) : false;
|
||||
return $temp != false ? $temp : $str;
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace phpseclib3\File;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use ParagonIE\ConstantTime\Hex;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Crypt\Common\PrivateKey;
|
||||
use phpseclib3\Crypt\Common\PublicKey;
|
||||
use phpseclib3\Crypt\DSA;
|
||||
@ -550,7 +550,7 @@ class X509
|
||||
return $cert;
|
||||
// case self::FORMAT_PEM:
|
||||
default:
|
||||
return "-----BEGIN CERTIFICATE-----\r\n" . chunk_split(Base64::encode($cert), 64) . '-----END CERTIFICATE-----';
|
||||
return "-----BEGIN CERTIFICATE-----\r\n" . chunk_split(Strings::base64_encode($cert), 64) . '-----END CERTIFICATE-----';
|
||||
}
|
||||
}
|
||||
|
||||
@ -1101,7 +1101,7 @@ class X509
|
||||
}
|
||||
$path = $parts['path'];
|
||||
if (isset($parts['query'])) {
|
||||
$path.= '?' . $parts['query'];
|
||||
$path .= '?' . $parts['query'];
|
||||
}
|
||||
fputs($fsock, "GET $path HTTP/1.0\r\n");
|
||||
fputs($fsock, "Host: $parts[host]\r\n\r\n");
|
||||
@ -2173,7 +2173,7 @@ class X509
|
||||
return $csr;
|
||||
// case self::FORMAT_PEM:
|
||||
default:
|
||||
return "-----BEGIN CERTIFICATE REQUEST-----\r\n" . chunk_split(Base64::encode($csr), 64) . '-----END CERTIFICATE REQUEST-----';
|
||||
return "-----BEGIN CERTIFICATE REQUEST-----\r\n" . chunk_split(Strings::base64_encode($csr), 64) . '-----END CERTIFICATE REQUEST-----';
|
||||
}
|
||||
}
|
||||
|
||||
@ -2198,7 +2198,7 @@ class X509
|
||||
|
||||
// OpenSSL produces SPKAC's that are preceded by the string SPKAC=
|
||||
$temp = preg_replace('#(?:SPKAC=)|[ \r\n\\\]#', '', $spkac);
|
||||
$temp = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $temp) ? Base64::decode($temp) : false;
|
||||
$temp = preg_match('#^[a-zA-Z\d/+]*={0,2}$#', $temp) ? Strings::base64_decode($temp) : false;
|
||||
if ($temp != false) {
|
||||
$spkac = $temp;
|
||||
}
|
||||
@ -2273,7 +2273,7 @@ class X509
|
||||
default:
|
||||
// OpenSSL's implementation of SPKAC requires the SPKAC be preceded by SPKAC= and since there are pretty much
|
||||
// no other SPKAC decoders phpseclib will use that same format
|
||||
return 'SPKAC=' . Base64::encode($spkac);
|
||||
return 'SPKAC=' . Strings::base64_encode($spkac);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2387,7 +2387,7 @@ class X509
|
||||
return $crl;
|
||||
// case self::FORMAT_PEM:
|
||||
default:
|
||||
return "-----BEGIN X509 CRL-----\r\n" . chunk_split(Base64::encode($crl), 64) . '-----END X509 CRL-----';
|
||||
return "-----BEGIN X509 CRL-----\r\n" . chunk_split(Strings::base64_encode($crl), 64) . '-----END X509 CRL-----';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -278,7 +278,7 @@ KQmi+cIHJHLONdX/3Im+M17V0iNAh7Z1lOSfTRT+iiwe/F8phcEaD5q2RmvYusR7
|
||||
zXZq/cLL0If0hXoPZ/EHQxjN8pxzxiUx6bJAgturnIMEfRNesxwghdr1dkUjOhGL
|
||||
f3kHVzgM6j3VAM7oFmMUb5y5s96Bzl10DodWitjOEH0vvnIcsppSxH1C1dCAi0o9
|
||||
f/1y2XuLNhBNHMAyTqpYPX8Yvav1c+Z50OMaSXHAnTa20zv8UtiHbaAhwlifCelU
|
||||
Mj93S
|
||||
Mj93
|
||||
-----END CERTIFICATE-----');
|
||||
$x509->loadX509($x509->saveX509($decoded));
|
||||
$expected = [
|
||||
@ -357,7 +357,7 @@ KQmi+cIHJHLONdX/3Im+M17V0iNAh7Z1lOSfTRT+iiwe/F8phcEaD5q2RmvYusR7
|
||||
zXZq/cLL0If0hXoPZ/EHQxjN8pxzxiUx6bJAgturnIMEfRNesxwghdr1dkUjOhGL
|
||||
f3kHVzgM6j3VAM7oFmMUb5y5s96Bzl10DodWitjOEH0vvnIcsppSxH1C1dCAi0o9
|
||||
f/1y2XuLNhBNHMAyTqpYPX8Yvav1c+Z50OMaSXHAnTa20zv8UtiHbaAhwlifCelU
|
||||
Mj93S
|
||||
Mj93
|
||||
-----END CERTIFICATE-----');
|
||||
$this->assertFalse($x509->validateSignature());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user