PHP code example of salibhdr / typhoon-url-signer

1. Go to this page and download the library: Download salibhdr/typhoon-url-signer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

salibhdr / typhoon-url-signer example snippets


'providers' => [

     // Other service providers...
     
     SaliBhdr\UrlSigner\Laravel\ServiceProviders\UrlSignerServiceProvider::class,
],

$app->register(SaliBhdr\UrlSigner\Laravel\ServiceProviders\UrlSignerServiceProvider::class);


$url = 'www.example.com/api/v1/book?timestamp=153664546&id=2';


$signedUrl = $urlSigner->create($url);



$url = 'www.example.com/api/v1/book';

$params = [
    'timestamp' => '153664546',
    'id' => 2
];

$signedUrl = $urlSigner->create($url,$params);




use SaliBhdr\UrlSigner\Md5UrlSigner;

//your sign key
$signKey = 'EKtF4lFP6D1FjBGtSRIk1gGn2YCRmtGPocBWV39wAeM=';
// default ttl is 7200 seconds
// pass null to make url's without expire time
$ttl = 7200; 

$urlSigner = new Md5UrlSigner($signKey,$ttl);




use SaliBhdr\UrlSigner\HmacUrlSigner;

//your sign key
$signKey = 'EKtF4lFP6D1FjBGtSRIk1gGn2YCRmtGPocBWV39wAeM=';
$algorithm = 'sha1';
// default ttl is 7200 seconds
// pass null to make url's without expire time
$ttl = 7200; 

$urlSigner = new HmacUrlSigner($signKey,$algorithm,$ttl);




use SaliBhdr\UrlSigner\Signers\Md5;
use SaliBhdr\UrlSigner\Signers\Hmac;
use SaliBhdr\UrlSigner\Signers\Rsa;
use phpseclib\Crypt\RSA as BaseRSA;

//-------------Md5 signer example-------------
//your sign key
$signKey = 'EKtF4lFP6D1FjBGtSRIk1gGn2YCRmtGPocBWV39wAeM=';

$signer = new Md5($signKey);

//-------------Hmac signer example------------

$signer = new Hmac($signKey);

//-------------Rsa signer example-------------

/* Rsa needs 2 extra parameters
 * a public_key and a private_key
 * It will not work if you don't provide these two
 */
$algorithm = 'sha1'; // default is sha256
$signMode = BaseRSA::SIGNATURE_PKCS1;

$signer = new Rsa($algorithm,$signMode);

$signer->setPublicKey('----RSA PUBLIC KEY HERE----');
$signer->setPrivateKey('----RSA PRIVATE KEY HERE----');




use SaliBhdr\UrlSigner\Signatures\Signature;

// default ttl is 7200 seconds
// pass null to make url's without expire time
$ttl = 7200; 

$signature = new Signature($signer,$ttl);




use SaliBhdr\UrlSigner\UrlSigner;

$urlSigner = new UrlSigner($signature);




$url = 'www.example.com/api/v1/book';

$params = [
    'timestamp' => '153664546',
    'id' => 2
];

$signedUrl = $urlSigner->create($url,$params);




// throws exception
$urlSigner->validate($signedUrl);

// returns true/false
echo $urlSigner->isValid($signedUrl) ? 'valid' : 'notValid';




use UrlSigner;

$url = 'www.example.com/api/v1/book?timestamp=153664546&id=2';

$signedUrl = UrlSigner::create($url);



use SaliBhdr\UrlSigner\Laravel\Facades\UrlSigner;

$url = 'www.example.com/api/v1/book';

$params = [
    'timestamp' => '153664546',
    'id' => 2
];

$signedUrl = UrlSigner::create($url, $params);




//throws exception
UrlSigner::validate($signedUrl);

// returns true/false
echo UrlSigner::isValid($signedUrl) ? 'valid':'notValid';

sh
php artisan vendor:publish --provider="SaliBhdr\UrlSigner\Laravel\ServiceProviders\UrlSignerServiceProvider"
sh
php artisan urlSigner:generate
sh
php artisan urlSigner:generate