Implementation of the RSA public key encryption algorithm.

package Default

 Methods

Class constructor

__construct(\Zend\Crypt\PublicKey\RsaOptions $options = null

Parameters

$options

\Zend\Crypt\PublicKey\RsaOptions

Exceptions

\Zend\Crypt\PublicKey\Rsa\Exception\RuntimeException

Decrypt with private/public key

decrypt(string $data, \Zend\Crypt\PublicKey\Rsa\AbstractKey $key = null, integer $mode = self::MODE_AUTO, null|integer $padding = null) : string

$data can be encoded in base64 or not. $mode sets how the input must be processed:

  • MODE_AUTO: Check if the $signature is encoded in base64. Not recommended for performance.
  • MODE_BASE64: Decode $data using base64 algorithm.
  • MODE_RAW: $data is not encoded.
see
see
see

Parameters

$data

string

$key

\Zend\Crypt\PublicKey\Rsa\AbstractKey

$mode

integer

Input encoding

$padding

nullinteger

An OPENSSL_*_PADDING constant value.

Exceptions

\Zend\Crypt\PublicKey\Rsa\Exception\InvalidArgumentException

Returns

string

Encrypt with private/public key

encrypt(string $data, \Zend\Crypt\PublicKey\Rsa\AbstractKey $key = null, null|integer $padding = null) : string

Parameters

$data

string

$key

\Zend\Crypt\PublicKey\Rsa\AbstractKey

$padding

nullinteger

An OPENSSL_*_PADDING constant value.

Exceptions

\Zend\Crypt\PublicKey\Rsa\Exception\InvalidArgumentException

Returns

string

RSA instance factory

factory(array|\Traversable $options) : \Zend\Crypt\PublicKey\Rsa
Static

Parameters

$options

array\Traversable

Exceptions

\Zend\Crypt\PublicKey\Rsa\Exception\RuntimeException
\Zend\Crypt\PublicKey\Rsa\Exception\InvalidArgumentException

Returns

\Zend\Crypt\PublicKey\Rsa

Generate new private/public key pair

generateKeys(array $opensslConfig = array()) : \Zend\Crypt\PublicKey\Rsa
see

Parameters

$opensslConfig

array

Exceptions

\Zend\Crypt\PublicKey\Rsa\Exception\RuntimeException

Returns

\Zend\Crypt\PublicKey\Rsa

Return last openssl error(s)

getOpensslErrorString() : string

Returns

string

Get options

getOptions() : \Zend\Crypt\PublicKey\RsaOptions

Returns

\Zend\Crypt\PublicKey\RsaOptions

Set options

setOptions(\Zend\Crypt\PublicKey\RsaOptions $options) : \Zend\Crypt\PublicKey\Rsa

Parameters

$options

\Zend\Crypt\PublicKey\RsaOptions

Returns

\Zend\Crypt\PublicKey\Rsa

Sign with private key

sign(string $data, \Zend\Crypt\PublicKey\Rsa\PrivateKey $privateKey = null) : string

Parameters

$data

string

$privateKey

\Zend\Crypt\PublicKey\Rsa\PrivateKey

Exceptions

\Zend\Crypt\PublicKey\Rsa\Exception\RuntimeException

Returns

string

Verify signature with public key

verify(string $data, string $signature, null|\Zend\Crypt\PublicKey\Rsa\PublicKey $publicKey = null, integer $mode = self::MODE_AUTO) : boolean

$signature can be encoded in base64 or not. $mode sets how the input must be processed:

  • MODE_AUTO: Check if the $signature is encoded in base64. Not recommended for performance.
  • MODE_BASE64: Decode $signature using base64 algorithm.
  • MODE_RAW: $signature is not encoded.
see
see
see

Parameters

$data

string

$signature

string

$publicKey

null\Zend\Crypt\PublicKey\Rsa\PublicKey

$mode

integer

Input encoding

Exceptions

\Zend\Crypt\PublicKey\Rsa\Exception\RuntimeException

Returns

boolean

 Properties

 

$options

$options : \Zend\Crypt\PublicKey\RsaOptions

Default

null

 Constants

 

MODE_AUTO

MODE_AUTO = 1 
 

MODE_BASE64

MODE_BASE64 = 2 
 

MODE_RAW

MODE_RAW = 3