|
1 | 1 | # PHP-Sharp
|
2 | 2 | [](https://packagist.org/packages/carry0987/sharp)
|
3 | 3 | A PHP script for generating signed and encrypted URLs for image processing with **[Sharp-API](https://github.com/carry0987/Sharp-API/)**, using AES-256-CBC and HMAC-SHA256.
|
| 4 | + |
| 5 | +## Installation |
| 6 | +Use Composer to install PHP-Sharp Image Encryptor in your project: |
| 7 | + |
| 8 | +```shell |
| 9 | +composer require carry0987/sharp |
| 10 | +``` |
| 11 | + |
| 12 | +## Configuration |
| 13 | +To use PHP-Sharp, you need to have a signature key, a signature salt, and a source key for encryption and hashing. These should be provided as hexadecimal strings. |
| 14 | + |
| 15 | +## Usage |
| 16 | +Below is an example demonstrating how to encrypt an image URL using PHP-Sharp Image Encryptor: |
| 17 | + |
| 18 | +```php |
| 19 | +require_once 'vendor/autoload.php'; |
| 20 | + |
| 21 | +use carry0987\Sharp\Sharp; |
| 22 | + |
| 23 | +// Initialize the keys and salt. Replace these values with your actual keys and salt. |
| 24 | +$signatureKey = 'your_hex_signature_key'; |
| 25 | +$signatureSalt = 'your_hex_signature_salt'; |
| 26 | +$sourceKey = 'your_hex_source_key'; |
| 27 | + |
| 28 | +// Create a new instance of PHP-Sharp Image Encryptor. |
| 29 | +$imageEncryptor = new Sharp($signatureKey, $signatureSalt, $sourceKey); |
| 30 | + |
| 31 | +// The URL of the image you want to encrypt. |
| 32 | +$originalImageUrl = 'https://example.com/image.jpg'; |
| 33 | + |
| 34 | +try { |
| 35 | + // Generate the encrypted and signed URL. |
| 36 | + $signedUrl = $imageEncryptor->generateEncryptedUrl($originalImageUrl); |
| 37 | + echo 'Encrypted and signed URL: ' . $signedUrl; |
| 38 | +} catch (\carry0987\Sharp\Exceptions\SharpException $e) { |
| 39 | + // Handle any exceptions during the encryption process. |
| 40 | + echo "Error occurred: " . $e->getMessage(); |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +## Contributing |
| 45 | +Contributions to PHP-Sharp Image Encryptor are welcome! Feel free to submit pull requests to improve the codebase. |
| 46 | + |
| 47 | +## License |
| 48 | +This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details. |
0 commit comments