[ Index ]

PHP Cross Reference of DokuWiki




/vendor/phpseclib/phpseclib/phpseclib/Crypt/ -> RSA.php (summary)

Pure-PHP PKCS#1 (v2.1) compliant implementation of RSA. PHP version 5

Author: Jim Wigginton
Copyright: 2009 Jim Wigginton
License: http://www.opensource.org/licenses/mit-license.html MIT License
Link: http://phpseclib.sourceforge.net
File Size: 934 lines (28 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 25 functions


Functions that are not part of a class:

setExponent($val)   X-Ref
Sets the public exponent for key generation

This will be 65537 unless changed.

param: int $val

setSmallestPrime($val)   X-Ref
Sets the smallest prime number in bits. Used for key generation

This will be 4096 unless changed.

param: int $val

setOpenSSLConfigPath($val)   X-Ref
Sets the OpenSSL config file path

Set to the empty string to use the default config file

param: string $val

createKey($bits = 2048)   X-Ref
Create a private key

The public key can be extracted from the private key

return: RSA\PrivateKey
param: int $bits

onLoad(array $components)   X-Ref
OnLoad Handler

return: bool

initialize_static_variables()   X-Ref
Initialize static variables

__construct()   X-Ref

PublicKey and PrivateKey objects can only be created from abstract RSA class

i2osp($x, $xLen)   X-Ref
Integer-to-Octet-String primitive

See {@link http://tools.ietf.org/html/rfc3447#section-4.1 RFC3447#section-4.1}.

return: bool|string
param: bool|\phpseclib3\Math\BigInteger $x
param: int $xLen

os2ip($x)   X-Ref
Octet-String-to-Integer primitive

See {@link http://tools.ietf.org/html/rfc3447#section-4.2 RFC3447#section-4.2}.

return: \phpseclib3\Math\BigInteger
param: string $x

emsa_pkcs1_v1_5_encode($m, $emLen)   X-Ref

See {@link http://tools.ietf.org/html/rfc3447#section-9.2 RFC3447#section-9.2}.

return: string
param: string $m
param: int $emLen

emsa_pkcs1_v1_5_encode_without_null($m, $emLen)   X-Ref

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

return: string
param: string $m
param: int $emLen

mgf1($mgfSeed, $maskLen)   X-Ref

See {@link http://tools.ietf.org/html/rfc3447#appendix-B.2.1 RFC3447#appendix-B.2.1}.

return: string
param: string $mgfSeed
param: int $maskLen

getLength()   X-Ref
Returns the key size

More specifically, this returns the size of the modulo in bits.

return: int

withHash($hash)   X-Ref
Determines which hashing function should be used

Used with signature production / verification and (if the encryption mode is self::PADDING_OAEP) encryption and

param: string $hash

withMGFHash($hash)   X-Ref
Determines which hashing function should be used for the mask generation function

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.

param: string $hash

getMGFHash()   X-Ref
Returns the MGF hash algorithm currently being used

withSaltLength($sLen)   X-Ref
Determines the salt length


To quote from {@link http://tools.ietf.org/html/rfc3447#page-38 RFC3447#page-38}:

Typical salt lengths in octets are hLen (the length of the output
of the hash function Hash) and 0.

param: int $sLen

getSaltLength()   X-Ref
Returns the salt length currently being used

withLabel($label)   X-Ref
Determines the label


To quote from {@link http://tools.ietf.org/html/rfc3447#page-17 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.

param: string $label

getLabel()   X-Ref
Returns the label currently being used

withPadding($padding)   X-Ref
Determines the padding modes

Example: $key->withPadding(RSA::ENCRYPTION_PKCS1 | RSA::SIGNATURE_PKCS1);

param: int $padding

getPadding()   X-Ref
Returns the padding currently being used

getEngine()   X-Ref
Returns the current engine being used

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

return: string
see: self::useInternalEngine()
see: self::useBestEngine()

enableBlinding()   X-Ref
Enable RSA Blinding

disableBlinding()   X-Ref
Disable RSA Blinding