FastSitePHP\Security\Crypto\PublicKey

Public Key Generator

Used to generate RSA Keys which can be used for JWT Signing. Function parameters allow for generation of additional public and private key types.

源代码

GitHub

示例代码

Security - Generate a new RSA Key Pair

// Generate a new RSA Key Pair
$key_pair = \FastSitePHP\Security\Crypto\PublicKey::generateRsaKeyPair();
list($private_key, $public_key) = $key_pair;

// Generate a new 3072-Bit RSA Key
$bits = 3072;
$key_pair = \FastSitePHP\Security\Crypto\PublicKey::generateRsaKeyPair($bits);
list($private_key2, $public_key2) = $key_pair;

方法

defaultConfig($bits = 2048)

静态功能

Return the default config options used when generating a new Key Pair. This an array of options set for a 2048-bit RSA Key.

2048-bit is used as because it is provides a combination of acceptable speed for JWT and strong security. If a JWT needs to be signed and validated after the year 2030 then a 3072-bit key is recommended, however 3072-bit keys are much slower to create.

On Windows this will attempt to find and set the [openssl.cnf] file for the instance of PHP that is running. This option is generally required in order to generate RSA Key Pairs on Windows. The file if found by default will exist at a location such as:
    C:\Program Files\PHP\v7.2\extras\ssl\openssl.cnf

返回类型: array

generateRsaKeyPair($bits = 2048)

静态功能

Generate a new RSA Key Pair

返回类型: array - [private_key, public_key]

generateKeyPair(array $config)

静态功能

Generate a new Public/Private Key Pair

返回类型: array - [private_key, public_key]