Documentation

CRM_Core_Key
in package

Tags
copyright

CiviCRM LLC https://civicrm.org/licensing

Table of Contents

Constants

HASH_ALGO  = 'sha256'
HASH_LENGTH  = 25
The minimum length of a generated signature/digest (expressed in base36 digits).
PRIVATE_KEY_LENGTH  = 16
The length of the randomly-generated, per-session signing key.

Properties

$_key  : mixed
$_sessionID  : mixed

Methods

get()  : string
Generate a form key based on form name, the current user session and a private key. Modelled after drupal's form API
privateKey()  : string
Generate a private key per session and store in session.
sessionID()  : mixed|null|string
valid()  : bool
Check that the key is well-formed. This does not check that the key is currently a key that is in use or belongs to a real form/session.
validate()  : string|null
Validate a form key based on the form name.
sign()  : string

Constants

HASH_ALGO

public string HASH_ALGO = 'sha256'
Tags
see
hash_hmac_algos()

HASH_LENGTH

The minimum length of a generated signature/digest (expressed in base36 digits).

public int HASH_LENGTH = 25

PRIVATE_KEY_LENGTH

The length of the randomly-generated, per-session signing key.

public int PRIVATE_KEY_LENGTH = 16

Expressed as number of bytes. (Ex: 128 bits = 16 bytes)

Properties

$_key

public static mixed $_key = \NULL

$_sessionID

public static mixed $_sessionID = \NULL

Methods

get()

Generate a form key based on form name, the current user session and a private key. Modelled after drupal's form API

public static get(string $name[, bool $addSequence = FALSE ]) : string
Parameters
$name : string
$addSequence : bool = FALSE

Should we add a unique sequence number to the end of the key.

Return values
string

valid formID

privateKey()

Generate a private key per session and store in session.

public static privateKey() : string
Return values
string

private key for this session

sessionID()

public static sessionID() : mixed|null|string
Return values
mixed|null|string

valid()

Check that the key is well-formed. This does not check that the key is currently a key that is in use or belongs to a real form/session.

public static valid(string $key) : bool
Parameters
$key : string
Return values
bool

TRUE if the signature ($key) is well-formed.

validate()

Validate a form key based on the form name.

public static validate(string $key, string $name[, bool $addSequence = FALSE ]) : string|null
Parameters
$key : string
$name : string
$addSequence : bool = FALSE
Return values
string|null

if valid, else null

sign()

private static sign(string $name) : string
Parameters
$name : string

The name of the form

Return values
string

A signed digest of $name, computed with the per-session private key


        
On this page

Search results