CRM_Utils_Signer
in package
A utility which signs and verifies a list of key-value pairs
FIXME: Add TTL support?
$signer = new CRM_Utils_Signer('myprivatekey', array('param1','param2'));
$params = array(
'param1' => 'hello',
'param2' => 'world',
);
$token = $signer->sign($params);
...
assertTrue($signer->validate($token, $params));
Table of Contents
Constants
- SALT_LEN = 4
- Expected length of the salt
Properties
- $signDelim : string
- $defaultSalt : string
- $paramNames : array<string|int, mixed>
- $secret : string
Methods
- __construct() : mixed
- Instantiate a signature-processor
- createSalt() : string
- sign() : mixed
- Generate a signature for a set of key-value pairs
- validate() : mixed
- Determine whether a token represents a proper signature for $params
Constants
SALT_LEN
Expected length of the salt
public
int
SALT_LEN
= 4
Properties
$signDelim
public
string
$signDelim
$defaultSalt
private
string
$defaultSalt
$paramNames
private
array<string|int, mixed>
$paramNames
$secret
private
string
$secret
Methods
__construct()
Instantiate a signature-processor
public
__construct(string $secret, array<string|int, mixed> $paramNames) : mixed
Parameters
- $secret : string
-
private.
- $paramNames : array<string|int, mixed>
-
Array, fields which should be part of the signature.
createSalt()
public
createSalt() : string
Return values
stringsign()
Generate a signature for a set of key-value pairs
public
sign(array<string|int, mixed> $params[, string $salt = NULL ]) : mixed
Parameters
- $params : array<string|int, mixed>
-
Array, key-value pairs.
- $salt : string = NULL
-
the salt (if known) or NULL (for auto-generated).
Tags
validate()
Determine whether a token represents a proper signature for $params
public
validate(string $token, array<string|int, mixed> $params) : mixed
Parameters
- $token : string
-
the full public token representing the signature.
- $params : array<string|int, mixed>
-
Array, key-value pairs.