Download the PHP package barseghyanartur/ska without Composer
On this page you can find all versions of the php package barseghyanartur/ska. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download barseghyanartur/ska
More information about barseghyanartur/ska
Files in barseghyanartur/ska
Package ska
Short Description Sign data using symmetric-key algorithm encryption. Validate signed data and identify possible validation errors. Uses sha-(1, 224, 256, 385 and 512)/hmac for signature encryption. Custom hash algorithms are allowed. Useful shortcut functions for signing (and validating) dictionaries and URLs.
License MIT
Homepage https://github.com/barseghyanartur/skaphp
Informations about the package ska
ska
Lets you easily sign data, using symmetric-key algorithm encryption. Allows you to validate signed data and identify possible validation errors. Uses sha/hmac for signature encryption. Comes with shortcut functions for signing (and validating) dictionaries (associative arrays).
Key concepts
Hosts, that communicate with each other, share the Secret Key, which is used to sign data (requests). Secret key is never sent around.
One of the cases is signing of HTTP requests. Each (HTTP) request is signed
on the sender side using the shared Secret Key and as an outcome produces the
triple (signature
, auth_user
, valid_until
) which are used to sign
the requests.
signature
(string
): Signature generated.auth_user
(string
): User making the request. Can be anything.valid_until
(float
orstring
): Signature expiration time (Unix timestamp).
On the recipient side, (HTTP request) data is validated using the shared Secret Key. It's being checked whether signature is valid and not expired.
Features
- Sign dictionaries.
- Validate signed dictionaries.
Prerequisites
- composer
- php-json
- php-mbstring
Eco-system
Need ska
for other languages? Check the following affiliated projects:
- ska:
ska
implementation for Python. This was the first implementation from which current project originated. - skajs:
ska
implementation for NodeJS (both CommonJS and ESM are supported, Node >= 14).
Generated signatures are intercompatible between Python, NodeJS and PHP implementations.
Installation
Latest stable version from composer registry:
Usage examples
Usage example are present.
Basic usage
Sender side
Signing dictionaries is as simple as follows.
Required imports.
Sign data
Sample usage:
Sample output:
Adding of additional data to the signature works in the same way:
Sample output:
Options and defaults:
The signatureToDict
function accepts an optional $options
argument.
Default value for the validUntil
in the $options
is 10 minutes from now. If
you want it to be different, set validUntil
in the $options
of
the signatureToDict
function.
Default lifetime of a signature is 10 minutes (600 seconds). If you want it
to be different, set lifetime
in the $options
of the signatureToDict
function.
Default name of the (GET) param holding the generated signature value
is signature
. If you want it to be different, set the signatureParam
in the $options
of the signatureToDict
function.
Default name of the (GET) param holding the authUser
value is
auth_user
. If you want it to be different, set authUserParam
in the $options
of the signatureToDict
function.
Default name of the (GET) param holding the validUntil
value is
valid_until
. If you want it to be different, set the validUntilParam
in the $options
of the signatureToDict
function.
Default name of the (GET) param holding the extra
value is
extra
. If you want it to be different, set the extraParam
in the $options
of the signatureToDict
function.
Sample output:
Recipient side
Validating the signed request data is as simple as follows.
Validate signed requests
Validating the signed request data. Note, that $data
value is expected to
be a dictionary; $request->GET
is given as an example.
Options and defaults:
Similarly to signatureToDict
function, the validateSignedRequestData
also accepts a number of optional arguments (which have been described above):
- signatureParam
- authUserParam
- validUntilParam
- extraParam
With some customizations, it would look as follows:
Testing
Simply type:
Code style
The Prettier
is used.
License
MIT
Support
For any issues contact me at the e-mail given in the Author section.
Author
Artur Barseghyan [email protected]
All versions of ska with dependencies
ext-json Version *
ext-mbstring Version *