mirror of
https://github.com/phpseclib/phpseclib.git
synced 2024-06-07 02:50:49 +00:00
use libsodium's base64 decoding if available
This commit is contained in:
parent
ea94a73380
commit
e5396968c5
|
@ -13,6 +13,8 @@
|
|||
|
||||
namespace phpseclib3\Common\Functions;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use ParagonIE\ConstantTime\Base64UrlSafe;
|
||||
use phpseclib3\Math\BigInteger;
|
||||
use phpseclib3\Math\Common\FiniteField;
|
||||
|
||||
|
@ -414,4 +416,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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
namespace phpseclib3\Crypt\Common\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Crypt\AES;
|
||||
use phpseclib3\Crypt\Random;
|
||||
|
@ -72,7 +71,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');
|
||||
|
@ -216,7 +215,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";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
namespace phpseclib3\Crypt\Common\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use ParagonIE\ConstantTime\Hex;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Crypt\AES;
|
||||
|
@ -176,7 +175,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-----";
|
||||
}
|
||||
|
||||
|
@ -191,7 +190,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-----";
|
||||
}
|
||||
|
||||
|
@ -205,7 +204,7 @@ abstract class PKCS1 extends PKCS
|
|||
protected static function wrapPublicKey($key, $type)
|
||||
{
|
||||
return "-----BEGIN $type PUBLIC KEY-----\r\n" .
|
||||
chunk_split(Base64::encode($key), 64) .
|
||||
chunk_split(Strings::base64_encode($key), 64) .
|
||||
"-----END $type PUBLIC KEY-----";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
namespace phpseclib3\Crypt\Common\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Crypt\AES;
|
||||
use phpseclib3\Crypt\DES;
|
||||
|
@ -602,12 +601,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-----";
|
||||
}
|
||||
|
||||
|
@ -637,7 +636,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-----";
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
namespace phpseclib3\Crypt\Common\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use ParagonIE\ConstantTime\Hex;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Crypt\AES;
|
||||
|
@ -197,7 +196,7 @@ abstract class PuTTY
|
|||
$components['comment'] = trim(preg_replace('#Comment: (.+)#', '$1', $key[2]));
|
||||
|
||||
$publicLength = 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);
|
||||
|
||||
|
@ -250,7 +249,7 @@ abstract class PuTTY
|
|||
}
|
||||
|
||||
$privateLength = 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);
|
||||
|
@ -297,7 +296,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);
|
||||
|
||||
|
@ -347,7 +346,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";
|
||||
|
@ -369,7 +368,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;
|
||||
}
|
||||
|
|
|
@ -27,11 +27,11 @@
|
|||
|
||||
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
|
||||
|
@ -93,7 +93,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";
|
||||
}
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
|
||||
namespace phpseclib3\Crypt\DSA\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Exception\BadConfigurationException;
|
||||
use phpseclib3\Math\BigInteger;
|
||||
|
@ -66,7 +65,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
|
||||
|
@ -124,10 +123,10 @@ abstract class XML
|
|||
public static function savePublicKey(BigInteger $p, BigInteger $q, BigInteger $g, BigInteger $y)
|
||||
{
|
||||
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>';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
|
||||
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;
|
||||
|
@ -156,7 +155,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";
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
|
||||
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;
|
||||
|
@ -64,7 +63,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) {
|
||||
|
@ -96,7 +95,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]);
|
||||
list(, $length) = unpack('N', Strings::shift($public, 4));
|
||||
Strings::shift($public, $length);
|
||||
|
||||
|
@ -127,7 +126,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]);
|
||||
list(, $length) = unpack('N', Strings::shift($public, 4));
|
||||
Strings::shift($public, $length);
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
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;
|
||||
|
@ -165,7 +164,7 @@ abstract class XML
|
|||
*/
|
||||
private static function decodeValue($value)
|
||||
{
|
||||
return Base64::decode(str_replace(["\r", "\n", ' ', "\t"], '', $value));
|
||||
return Strings::base64_decode(str_replace(["\r", "\n", ' ', "\t"], '', $value));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -401,7 +400,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>';
|
||||
}
|
||||
|
||||
|
@ -466,7 +465,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:
|
||||
|
@ -474,11 +473,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;
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
namespace phpseclib3\Crypt\RSA\Formats\Keys;
|
||||
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\Exception\UnsupportedFormatException;
|
||||
use phpseclib3\Math\BigInteger;
|
||||
|
@ -78,7 +77,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');
|
||||
|
@ -206,7 +205,7 @@ abstract class MSBLOB
|
|||
$key .= strrev($coefficients[2]->toBytes());
|
||||
$key .= strrev($d->toBytes());
|
||||
|
||||
return Base64::encode($key);
|
||||
return Strings::base64_encode($key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -224,6 +223,6 @@ abstract class MSBLOB
|
|||
$key .= pack('VVa*', self::RSA1, 8 * strlen($n), $e);
|
||||
$key .= $n;
|
||||
|
||||
return Base64::encode($key);
|
||||
return Strings::base64_encode($key);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
|
||||
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;
|
||||
|
@ -144,14 +143,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>';
|
||||
}
|
||||
|
||||
|
@ -165,8 +164,8 @@ abstract class XML
|
|||
public static function savePublicKey(BigInteger $n, BigInteger $e)
|
||||
{
|
||||
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>';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
namespace phpseclib3\File;
|
||||
|
||||
use DateTime;
|
||||
use ParagonIE\ConstantTime\Base64;
|
||||
use phpseclib3\Common\Functions\Strings;
|
||||
use phpseclib3\File\ASN1\Element;
|
||||
use phpseclib3\Math\BigInteger;
|
||||
|
@ -1462,7 +1461,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
|
||||
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;
|
||||
|
@ -558,7 +558,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-----';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1132,7 +1132,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");
|
||||
|
@ -2268,7 +2268,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-----';
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2296,7 +2296,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;
|
||||
}
|
||||
|
@ -2372,7 +2372,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2491,7 +2491,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-----';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -276,7 +276,7 @@ KQmi+cIHJHLONdX/3Im+M17V0iNAh7Z1lOSfTRT+iiwe/F8phcEaD5q2RmvYusR7
|
|||
zXZq/cLL0If0hXoPZ/EHQxjN8pxzxiUx6bJAgturnIMEfRNesxwghdr1dkUjOhGL
|
||||
f3kHVzgM6j3VAM7oFmMUb5y5s96Bzl10DodWitjOEH0vvnIcsppSxH1C1dCAi0o9
|
||||
f/1y2XuLNhBNHMAyTqpYPX8Yvav1c+Z50OMaSXHAnTa20zv8UtiHbaAhwlifCelU
|
||||
Mj93S
|
||||
Mj93
|
||||
-----END CERTIFICATE-----');
|
||||
$x509->loadX509($x509->saveX509($decoded));
|
||||
$expected = [
|
||||
|
@ -355,7 +355,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