carry0987/sharp

一个用于使用 Sharp-API 生成签名和加密 URL 的 PHP 库,采用 AES-256-GCM 和 HMAC-SHA256

1.2.2 2024-03-21 01:02 UTC

This package is auto-updated.

Last update: 2024-09-21 02:17:54 UTC


README

Packgist
一个用于使用 Sharp-API 生成签名和加密 URL 的 PHP 脚本,采用 AES-256-GCM 和 HMAC-SHA256。

安装

使用 Composer 在您的项目中安装 PHP-Sharp 图像加密器

composer require carry0987/sharp

配置

要使用 PHP-Sharp,您需要有一个签名密钥、一个签名盐和一个加密和哈希的源密钥。这些应提供为十六进制字符串。

用法

以下是一个演示如何使用 PHP-Sharp 图像加密器加密图像 URL 的示例

require_once 'vendor/autoload.php';

use carry0987\Sharp\Sharp;

// Initialize the keys and salt. Replace these values with your actual keys and salt.
$signatureKey = 'your_hex_signature_key';
$signatureSalt = 'your_hex_signature_salt';
$sourceKey = 'your_hex_source_key';

// Create a new instance of PHP-Sharp Image Encryptor.
$imageEncryptor = new Sharp($signatureKey, $signatureSalt, $sourceKey);

// The URL of the image you want to encrypt.
$originalImageUrl = 'https://example.com/image.jpg';

try {
    // Generate the encrypted and signed URL.
    $signedUrl = $imageEncryptor->generateEncryptedUrl($originalImageUrl);
    echo 'Encrypted and signed URL: ' . $signedUrl;
} catch (\carry0987\Sharp\Exceptions\SharpException $e) {
    // Handle any exceptions during the encryption process.
    echo "Error occurred: " . $e->getMessage();
}

贡献

欢迎为 PHP-Sharp 图像加密器做出贡献!请随意提交 pull 请求以改进代码库。

许可

本项目采用 MIT 许可证。有关详细信息,请参阅 LICENSE 文件。