\Pluf_Sign

Module to easily and possibly securily sign strings.

The goal is to avoid reinventing the wheel each time one needs to sign strings.

Usage to sign a string:

$signed = Pluf_Sign::sign($mystring);
// send the string over the wire
$mystring = Pluf_Sign::unsign($signed);

Usage to pack and sign an object:

$signed = Pluf_Sign::dumps($myobject);
// send the string over the wire
$myobject = Pluf_Sign::loads($signed);

Based on the work by Simon Willison: http://github.com/simonw/django-openid/blob/master/django_openid/signed.py

Summary

Methods
Properties
Constants
dumps()
loads()
sign()
unsign()
base64_hmac()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

dumps()

dumps(  $obj,   $key = null,   $compress = false,   $extra_key = '') : string

Dump and sign an object.

If you want to sign a small string, use directly the sign/unsign function as compression will not help and you will save the overhead of the serialize call.

Parameters

$obj
$key
$compress
$extra_key

Returns

string —

Signed string

loads()

loads(  $s,   $key = null,   $extra_key = '') : mixed

Reverse of dumps, throw an Exception in case of bad signature.

Parameters

$s
$key
$extra_key

Returns

mixed —

The dumped signed object

sign()

sign(  $value,   $key = null) : string

Sign a string.

If the key is not provided, it will use the secret_key available in the configuration file.

The signature string is safe to use in URLs. So if the string to sign is too, you can use the signed string in URLs.

Parameters

$value
$key

Returns

string —

Signed string

unsign()

unsign(  $signed_value,   $key = null) : string

Unsign a value.

It will throw an exception in case of error in the process.

Parameters

$signed_value
$key

Returns

string —

Signed string

base64_hmac()

base64_hmac(  $value,   $key) : string

Calculate the URL safe base64 encoded SHA1 hmac of a string.

Parameters

$value
$key

Returns

string —

The signature