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
asPrivateKey(): \phpseclib3\Crypt\RSA
bits2int(string $in): \phpseclib3\Math\BigInteger
bits2octets(string $in): string
string
string
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
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_verify(string $m,string $em,integer $emBits): string
enableBlinding()
encrypt(string $plaintext): boolean|string
Both self::PADDING_OAEP and self::PADDING_PKCS1 both place limits on how long $plaintext can be. If $plaintext exceeds those limits it will be broken up so that it does and the resultant ciphertext's will be concatenated together.
see | self::decrypt() |
---|---|
Throws |
|
string
boolean|string
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
getFingerprint(string $algorithm = 'md5'): mixed
The public key's fingerprint is returned, which is equivalent to running ssh-keygen -lf rsa.pub
. If there is
no public key currently loaded, false is returned.
Example output (md5): "c1:b1:30:29:d7:b8:de:6c:97:77:10:d7:46:41:63:87" (as specified by RFC 4716)
string
The hashing algorithm to be used. Valid options are 'md5' and 'sha256'. False is returned for invalid values.
mixed
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()
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
rsaep(\phpseclib3\Math\BigInteger $m): boolean|\phpseclib3\Math\BigInteger
rsaes_oaep_encrypt(string $m): string
See RFC3447#section-7.1.1 and {http://en.wikipedia.org/wiki/Optimal_Asymmetric_Encryption_Padding OAES}.
Throws |
|
---|
string
string
rsaes_pkcs1_v1_5_encrypt(string $m,boolean $pkcs15_compat = false): boolean|string
Throws |
|
---|
string
boolean
optional
boolean|string
rsassa_pkcs1_v1_5_relaxed_verify(string $m,string $s): boolean
Per RFC3447#page-43 PKCS1 v1.5 specified the use BER encoding rather than DER encoding that PKCS1 v2.0 specified. This means that under rare conditions you can have a perfectly valid v1.5 signature that fails to validate with _rsassa_pkcs1_v1_5_verify(). PKCS1 v2.1 also recommends that if you're going to validate these types of signatures you "should indicate whether the underlying BER encoding is a DER encoding and hence whether the signature is valid with respect to the specification given in [PKCS1 v2.0+]". so if you do $rsa->getLastPadding() and get RSA::PADDING_RELAXED_PKCS1 back instead of RSA::PADDING_PKCS1... that means BER encoding was used.
string
string
boolean
rsassa_pkcs1_v1_5_verify(string $m,string $s): boolean
Throws |
|
---|
string
string
boolean
rsassa_pss_verify(string $m,string $s): boolean|string
rsavp1(\phpseclib3\Math\BigInteger $s): boolean|\phpseclib3\Math\BigInteger
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
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
verify(string $message,string $signature): boolean
see | self::sign() |
---|
string
string
boolean
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
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 | |
---|---|
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