PHP code example of verdient / signature

1. Go to this page and download the library: Download verdient/signature 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/ */

    

verdient / signature example snippets


use Verdient\signature\Signature;

/**
 * 签名秘钥
 */
$key = '****';

/**
 * 编码器
 * 默认为signature\encoder\HmacEncoder
 * 系统内置了HmacEncoder和Base64Encoder,也可以通过实现EncoderInterface来实现自己的编码器
 * 可以通过数组的方式来配置,格式为
 * [
 *     'class' => {className}
 *     ${property1} => ${property1},
 *     ${property2} => ${property2},
 *     ...
 * ]
 */
$encoder = 'Verdient\signature\encoder\HmacEncoder';

$sign = new Signature([
	'key' => $key,
	'encoder ' => $encoder
]);

/**
 * 待签名的数据
 * 可以为字符串和数组
 */
$data = ['key1' => 1, 'key2' => 2, 'key3' => 3];

$signature = $sign->sign($data);

$sign->validate($data, $signature);