Static Public Member Functions | |
| static | dumps ($obj, $key=null, $compress=false, $extra_key='') |
| static | loads ($s, $key=null, $extra_key='') |
| static | sign ($value, $key=null) |
| static | unsign ($signed_value, $key=null) |
| static | base64_hmac ($value, $key) |
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
| static Pluf_Sign::dumps | ( | $ | obj, | |
| $ | key = null, |
|||
| $ | compress = false, |
|||
| $ | extra_key = '' | |||
| ) | [static] |
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.
| mixed | Object | |
| string | Key (null) | |
| bool | Compress with gzdeflate (false) | |
| string | Extra key not to use only the secret_key ('') |
| static Pluf_Sign::loads | ( | $ | s, | |
| $ | key = null, |
|||
| $ | extra_key = '' | |||
| ) | [static] |
Reverse of dumps, throw an Exception in case of bad signature.
| string | Signed key | |
| string | Key (null) | |
| string | Extra key ('') |
| static Pluf_Sign::sign | ( | $ | value, | |
| $ | key = null | |||
| ) | [static] |
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.
| string | The string to sign | |
| string | Optional key (null) |
| static Pluf_Sign::unsign | ( | $ | signed_value, | |
| $ | key = null | |||
| ) | [static] |
Unsign a value.
It will throw an exception in case of error in the process.
| string | Optional key (null) | |
| string | The string |
| static Pluf_Sign::base64_hmac | ( | $ | value, | |
| $ | key | |||
| ) | [static] |
Calculate the URL safe base64 encoded SHA1 hmac of a string.
| string | The string to sign | |
| string | The key |