pforret/digestif

这是我创建的 digestif 包

1.0.3 2023-09-14 09:05 UTC

This package is auto-updated.

Last update: 2024-09-08 10:07:42 UTC


README

Latest Version on Packagist Tests Total Downloads

用于创建字符串/数组的摘要的包,用于创建独特且难以猜测的 URL/文件夹名称。

安装

您可以通过 composer 安装此包

composer require pforret/digestif

使用方法

use Pforret\Digestif\Digestif;

$dig = new Digestif(env("DIGEST_SEED"));
// seed value should be unique for that server/application.
// It's important that it is not known to the outside world.
// It should be the same for the application creating the Digest as the one reading/verifying it 

$url = "https://secure.example.com/invoice/1200323";
// if you make your URL like this, the URL for the other invoices can be guessed (e.g. 1200324, etc)

$digest = $dig->fromString($url);
$secure_url = "$url/$digest";
// URL = https://secure.example.com/invoice/1200323/0a1b-2c3d
// using a route /invoice/{id}/{digest} will allow you to verify the digest
// the URL of the next invoice 1200324 cannot be guessed without knowing the seed value

// or use this
$secure_url = "$url?$digest";
//URL = https://secure.example.com/invoice/1200323?0a1b-2c3d
// and then verify the digest before showing the actual invoice
if(!$dig->compareDigest($dig->fromString($url), $digest)){
    return false;
}
// 0a1b-2c3d will be ok, as 0a1b2c3d (without dash)

## Testing

```bash
composer test

变更日志

请参阅 CHANGELOG 了解最近更改的信息。

贡献

请参阅 CONTRIBUTING 了解详细信息。

安全漏洞

请审查 我们的安全策略 了解如何报告安全漏洞。

致谢

许可证

MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。