Raw RSA Key Handler
author | Jim Wigginton terrafrost@php.net |
---|---|
package | Default |
__construct()
__toString(): string
string
addFileFormat(string $fullname): boolean
The plugin needs to either already be loaded or be auto-loadable. Loading a plugin whose shortname overwrite an existing shortname will overwrite the old plugin.
see | \phpseclib3\Crypt\Common\AsymmetricKey::load() |
---|
string
boolean
bits2int(string $in): \phpseclib3\Math\BigInteger
bits2octets(string $in): string
string
string
blind(\phpseclib3\Math\BigInteger $x,\phpseclib3\Math\BigInteger $r,integer $i): \phpseclib3\Math\BigInteger
Protects against timing attacks by employing RSA Blinding. Returns $x->modPow($this->exponents[$i], $this->primes[$i])
integer
\phpseclib3\Math\BigInteger
computek(string $h1): string
string
string
createKey(integer $bits = 2048): \phpseclib3\Crypt\RSA\PrivateKey
The public key can be extracted from the private key
integer
\phpseclib3\Crypt\RSA\PrivateKey
decrypt(string $ciphertext): boolean|string
see | self::encrypt() |
---|
string
boolean|string
disableBlinding()
emsa_pkcs1_v1_5_encode(string $m,integer $emLen): string
See RFC3447#section-9.2.
Throws |
|
---|
string
integer
string
emsa_pkcs1_v1_5_encode_without_null(string $m,integer $emLen): string
Quoting https://tools.ietf.org/html/rfc8017#page-65,
"The parameters field associated with id-sha1, id-sha224, id-sha256, id-sha384, id-sha512, id-sha512/224, and id-sha512/256 should generally be omitted, but if present, it shall have a value of type NULL"
string
integer
string
emsa_pss_encode(string $m,integer $emBits): string
Throws |
|
---|
string
integer
string
enableBlinding()
exponentiate(\phpseclib3\Math\BigInteger $x): \phpseclib3\Math\BigInteger
getComment(): null|string
Not all key formats support comments. If you want to set a comment use toString()
null|string
getEngine(): string
OpenSSL is only used in this class (and it's subclasses) for key generation Even then it depends on the parameters you're using. It's not used for multi-prime RSA nor is it used if the key length is outside of the range supported by OpenSSL
see | self::useInternalEngine()self::useBestEngine() |
---|---|
string
getHash()
getLabel()
getLength(): integer
More specifically, this returns the size of the modulo in bits.
integer
getLoadedFormat(): mixed
If the key that was loaded wasn't in a valid or if the key was auto-generated with RSA::createKey() then this will throw an exception.
see | \phpseclib3\Crypt\Common\AsymmetricKey::load() |
---|---|
mixed
getMGFHash()
getPadding()
getPublicKey(): mixed
mixed
getSaltLength()
getSupportedKeyFormats(): array
array
i2osp(boolean|\phpseclib3\Math\BigInteger $x,integer $xLen): boolean|string
See RFC3447#section-4.1.
boolean|\phpseclib3\Math\BigInteger
integer
boolean|string
initialize_static_variables()
int2octets(\phpseclib3\Math\BigInteger $v): string
load(string $key,string $password = false): \phpseclib3\Crypt\Common\AsymmetricKey
loadFormat(string $type,string $key,string $password = false): static
string
string
string
optional
static
loadParameters(string|array $key): \phpseclib3\Crypt\Common\AsymmetricKey
loadParametersFormat(string $type,string|array $key): \phpseclib3\Crypt\Common\AsymmetricKey
loadPlugins(string $format)
string
loadPrivateKey(string|array $key,string $password = ''): \phpseclib3\Crypt\Common\PrivateKey
loadPrivateKeyFormat(string $type,string $key,string $password = false): \phpseclib3\Crypt\Common\PrivateKey
string
string
string
optional
\phpseclib3\Crypt\Common\PrivateKey
loadPublicKey(string|array $key): \phpseclib3\Crypt\Common\PublicKey
loadPublicKeyFormat(string $type,string $key): \phpseclib3\Crypt\Common\PublicKey
mgf1(string $mgfSeed,integer $maskLen): string
onLoad(array $components): boolean
array
boolean
os2ip(string $x): \phpseclib3\Math\BigInteger
raw_encrypt(string $m): boolean|string
Doesn't use padding and is not recommended.
Throws |
|
---|
string
boolean|string
rsadp(\phpseclib3\Math\BigInteger $c): boolean|\phpseclib3\Math\BigInteger
rsaes_oaep_decrypt(string $c): boolean|string
See RFC3447#section-7.1.2. The fact that the error messages aren't distinguishable from one another hinders debugging, but, to quote from RFC3447#section-7.1.2:
Note. Care must be taken to ensure that an opponent cannot distinguish the different error conditions in Step 3.g, whether by error message or timing, or, more generally, learn partial information about the encoded message EM. Otherwise an opponent may be able to obtain useful information about the decryption of the ciphertext C, leading to a chosen-ciphertext attack such as the one observed by Manger [36].
string
boolean|string
rsaes_pkcs1_v1_5_decrypt(string $c): boolean|string
rsasp1(\phpseclib3\Math\BigInteger $m): boolean|\phpseclib3\Math\BigInteger
rsassa_pkcs1_v1_5_sign(string $m): boolean|string
Throws |
|
---|
string
boolean|string
rsassa_pss_sign(string $m): boolean|string
setExponent(integer $val)
This will be 65537 unless changed.
integer
setOpenSSLConfigPath(string $val)
Set to the empty string to use the default config file
string
setSmallestPrime(integer $val)
This will be 4096 unless changed.
integer
sign(string $message): string
see | self::verify() |
---|
string
string
toString(string $type,array $options = array()): string
string
array
string
useBestEngine()
useInternalEngine()
validatePlugin(string $format,string $type,string $method = null): mixed
string
string
string
optional
mixed
withHash(string $hash)
string
withLabel(string $label)
Used by RSA::PADDING_OAEP
To quote from RFC3447#page-17:
Both the encryption and the decryption operations of RSAES-OAEP take the value of a label L as input. In this version of PKCS #1, L is the empty string; other uses of the label are outside the scope of this document.
string
withMGFHash(string $hash)
The mask generation function is used by self::PADDING_OAEP and self::PADDING_PSS and although it's best if Hash and MGFHash are set to the same thing this is not a requirement.
string
withPadding(integer $padding)
Example: $key->withPadding(RSA::ENCRYPTION_PKCS1 | RSA::SIGNATURE_PKCS1);
integer
withPassword(string|boolean $password = false)
Private keys can be encrypted with a password. To unset the password, pass in the empty string or false. Or rather, pass in $password such that empty($password) && !is_string($password) is true.
see | self::createKey()self::load() |
---|---|
string|boolean
withSaltLength(integer $sLen)
Used by RSA::PADDING_PSS
To quote from RFC3447#page-38:
Typical salt lengths in octets are hLen (the length of the output of the hash function Hash) and 0.
integer
ALGORITHM
var |
---|
ENCRYPTION_OAEP
Uses sha256 by default
see | |
---|---|
ENCRYPTION_PKCS1
Although self::PADDING_OAEP / self::PADDING_PSS offers more security, including PKCS#1 padding is necessary for purposes of backwards compatibility with protocols (like SSH-1) written before OAEP's introduction.
see | |
---|---|
ENCRYPTION_NONE
Although this method is not recommended it can none-the-less sometimes be useful if you're trying to decrypt some legacy stuff, if you're trying to diagnose why an encrypted message isn't decrypting, etc.
see | |
---|---|
SIGNATURE_PSS
Uses sha256 and 0 as the salt length
see | |
---|---|
SIGNATURE_RELAXED_PKCS1
see | |
---|---|
SIGNATURE_PKCS1
see | |
---|---|
primes :array
var |
---|
array
exponents :array
var |
---|
array
coefficients :array
var |
---|
array
privateExponent :\phpseclib3\Math\BigInteger
password :string|boolean
var |
---|
string|boolean
encryptionPadding :integer
var |
---|
integer
signaturePadding :integer
var |
---|
integer
hLen :integer
var |
---|
integer
sLen :integer
var |
---|
integer
label :string
var |
---|
string
mgfHash :\phpseclib3\Crypt\Hash
mgfHLen :integer
var |
---|
integer
modulus :\phpseclib3\Math\BigInteger
exponent :\phpseclib3\Math\BigInteger
defaultExponent :integer
enableBlinding :boolean
var |
---|
boolean
configFile :\phpseclib3\Crypt\?string
see | |
---|---|
var |
\phpseclib3\Crypt\?string
smallestPrime :integer
Per http://cseweb.ucsd.edu/~hovav/dist/survey.pdf#page=5, this number ought not result in primes smaller than 256 bits. As a consequence if the key you're trying to create is 1024 bits and you've set smallestPrime to 384 bits then you're going to get a 384 bit prime and a 640 bit prime (384 + 1024 % 384). At least if engine is set to self::ENGINE_INTERNAL. If Engine is set to self::ENGINE_OPENSSL then smallest Prime is ignored (ie. multi-prime RSA support is more intended as a way to speed up RSA key generation when there's a chance neither gmp nor OpenSSL are installed)
var |
---|
integer
publicExponent :\phpseclib3\Math\BigInteger
zero :\phpseclib3\Math\BigInteger
one :\phpseclib3\Math\BigInteger
format :string
var |
---|
string
plugins :array
see | |
---|---|
var |
array
invisiblePlugins :array
see | |
---|---|
var |
array
engines :array<mixed,boolean>
var |
---|
array<mixed,boolean>
Key Comment
Type(s)
null|string