Pure-PHP PKCS#1 compliant implementation of RSA.
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
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
enableBlinding()
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()
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
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
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
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
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