diff --git a/phpseclib/Crypt/EC/Formats/Keys/PKCS1.php b/phpseclib/Crypt/EC/Formats/Keys/PKCS1.php index 838f430a..b28492bc 100644 --- a/phpseclib/Crypt/EC/Formats/Keys/PKCS1.php +++ b/phpseclib/Crypt/EC/Formats/Keys/PKCS1.php @@ -37,6 +37,7 @@ use ParagonIE\ConstantTime\Base64; use phpseclib3\Crypt\EC\BaseCurves\TwistedEdwards as TwistedEdwardsCurve; use phpseclib3\Crypt\EC\BaseCurves\Montgomery as MontgomeryCurve; use phpseclib3\Exception\UnsupportedCurveException; +use phpseclib3\Common\Functions\Strings; /** * "PKCS1" (RFC5915) Formatted EC Key Handler @@ -61,6 +62,10 @@ abstract class PKCS1 extends Progenitor { self::initialize_static_variables(); + if (!Strings::is_stringable($key)) { + throw new \UnexpectedValueException('Key should be a string - not a ' . gettype($key)); + } + if (strpos($key, 'BEGIN EC PARAMETERS') && strpos($key, 'BEGIN EC PRIVATE KEY')) { $components = [];