Zend Framework  3.0
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | List of all members
Rsa Class Reference

Implementation of the RSA public key encryption algorithm. More...

Public Member Functions

 __construct (RsaOptions $options=null)
 Class constructor.
 
 setOptions (RsaOptions $options)
 Set options.
 
 getOptions ()
 Get options.
 
 getOpensslErrorString ()
 Return last openssl error(s)
 
 sign ($data, Rsa\PrivateKey $privateKey=null)
 Sign with private key.
 
 verify ($data, $signature, Rsa\PublicKey $publicKey=null, $mode=self::MODE_AUTO)
 Verify signature with public key.
 
 encrypt ($data, Rsa\AbstractKey $key=null)
 Encrypt with private/public key.
 
 decrypt ($data, Rsa\AbstractKey $key=null, $mode=self::MODE_AUTO)
 Decrypt with private/public key.
 
 generateKeys (array $opensslConfig=[])
 Generate new private/public key pair.
 

Static Public Member Functions

static factory ($options)
 RSA instance factory.
 

Public Attributes

const MODE_AUTO = 1
 
const MODE_BASE64 = 2
 
const MODE_RAW = 3
 

Protected Attributes

 $options = null
 

Detailed Description

Implementation of the RSA public key encryption algorithm.

Constructor & Destructor Documentation

__construct ( RsaOptions  $options = null)

Class constructor.

Parameters
RsaOptions$options
Exceptions
Rsa\Exception\RuntimeException

Member Function Documentation

decrypt (   $data,
Rsa\AbstractKey  $key = null,
  $mode = self::MODE_AUTO 
)

Decrypt with private/public key.

$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.
Parameters
string$data
Rsa\AbstractKey$key
int$modeInput encoding
Returns
string
Exceptions
Rsa\Exception\InvalidArgumentException
See Also
Rsa::MODE_AUTO
Rsa::MODE_BASE64
Rsa::MODE_RAW
encrypt (   $data,
Rsa\AbstractKey  $key = null 
)

Encrypt with private/public key.

Parameters
string$data
Rsa\AbstractKey$key
Returns
string
Exceptions
Rsa\Exception\InvalidArgumentException
static factory (   $options)
static

RSA instance factory.

Parameters
array | Traversable$options
Returns
Rsa
Exceptions
Rsa\Exception\RuntimeException
Rsa\Exception\InvalidArgumentException
generateKeys ( array  $opensslConfig = [])

Generate new private/public key pair.

See Also
RsaOptions::generateKeys()
Parameters
array$opensslConfig
Returns
Rsa
Exceptions
Rsa\Exception\RuntimeException
getOpensslErrorString ( )

Return last openssl error(s)

Returns
string
getOptions ( )

Get options.

Returns
RsaOptions
setOptions ( RsaOptions  $options)

Set options.

Parameters
RsaOptions$options
Returns
Rsa
sign (   $data,
Rsa\PrivateKey  $privateKey = null 
)

Sign with private key.

Parameters
string$data
Rsa\PrivateKey$privateKey
Returns
string
Exceptions
Rsa\Exception\RuntimeException
verify (   $data,
  $signature,
Rsa\PublicKey  $publicKey = null,
  $mode = self::MODE_AUTO 
)

Verify signature with public key.

$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.
Parameters
string$data
string$signature
null | Rsa\PublicKey$publicKey
int$modeInput encoding
Returns
bool
Exceptions
Rsa\Exception\RuntimeException
See Also
Rsa::MODE_AUTO
Rsa::MODE_BASE64
Rsa::MODE_RAW

Member Data Documentation

$options = null
protected
const MODE_AUTO = 1
const MODE_BASE64 = 2
const MODE_RAW = 3