viradmin/encrypted_images_php

Encrypted Images PHP是一个用于将文本加密成图片以及将图片解密回文本的PHP库。

dev-main 2023-10-13 06:12 UTC

This package is auto-updated.

Last update: 2024-09-13 07:59:36 UTC


README

作者: Bruce Bates
版权: 2023
X: @thebrucebates
网站: https://encryptedimages.art

许可证

Encrypted Images PHP遵循MIT许可证发布。 License

安装

composer require viraladmin/encrypted_images_php

目录

  1. 简介
  2. 支持的字符
  3. 最小和最大字符数
  4. 安全性
  5. 水印
  6. 函数

简介

Encrypted Images PHP是一个用于将文本加密成图片以及将图片解密回文本的PHP库。

支持的字符

该库支持以下字符

  • 小写字母(a-z)
  • 大写字母(A-Z)
  • 等号(=)
  • 反斜杠(\)
  • 加号(+)

请注意,空格(" ")不被包括在支持的字符中。

最小和最大字符数

  • 最小字符数: 10
  • 最大字符数: 5,006,512 (内存耗尽)
    • 请注意,在将加密文本转换为图片时,可能更早出现内存耗尽。

安全性

此库对加密时间攻击具有安全性(PHP所能达到的最大安全性)。

水印

Encrypted Images PHP支持各种可以嵌入到图片中的水印。您可以从以下水印类型中选择

  • Ethereum
  • Bitcoin
  • Cardano

函数

文本加密

使用AES-128-CBC加密加密字符串并验证完整性以防止时间攻击。

参数

  • $str (字符串):要加密的输入字符串。
  • $key (字符串,可选):加密密钥。默认为 "welovenfts"。

返回值

  • (字符串|false):加密字符串或如果加密失败或完整性检查失败则返回false。

示例用法

require_once 'vendor/autoload.php';
use encrypted_images_php\encryption\text;

// Initialize the class
$textEncryptor = new text();

// Encrypt a string
$encryptedString = $textEncryptor->encrypt("Your secret message", 'encryption-key');

// Check if encryption was successful
if ($encryptedString !== false) {
    // Proceed with the encrypted data
} else {
    // Handle the encryption failure
}

图片加密

加密字符串并将其嵌入带有水印的图片中。

参数

  • $str (字符串):要加密的输入字符串。
  • $watermark (字符串,可选):水印类型(例如,'ethereum','bitcoin','cardano')。
  • $key (字符串,可选):加密密钥。默认为 "welovenfts"。
  • $r (整数,可选):顶部渐变调整。
  • $g (整数,可选):中间渐变调整。
  • $b (整数,可选):底部渐变调整。

返回值

  • (字符串):包含加密数据的Base64编码图片。

示例用法

require_once 'vendor/autoload.php';
use encrypted_images_php\encryption\images;

// Initialize the class
$imageEncryptor = new images();

// Encrypt a string and embed it into an image with a watermark
$imageData = $imageEncryptor->encryptToImage("Your secret message", 'ethereum', 'encryption-key', 100, 134, 131);

// Display or use the base64-encoded image data as needed
echo '<img src="data:image/png;base64,' . $imageData . '" alt="Encrypted Image" />';

文本解密

解密加密文本并返回原始明文。

参数

  • $text (字符串):要解密的加密文本。
  • $key (字符串,可选):解密密钥。默认为 "welovenfts"。

返回值

  • (字符串|数组):原始明文或错误信息。

示例用法

require_once 'vendor/autoload.php';
use encrypted_images_php\decryption\text;

// Initialize the class
$textDecryptor = new text();

// Decrypt an encrypted text
$decryptedText = $textDecryptor->decrypt($encryptedText, 'decryption-key');

if ($decryptedText !== 'error') {
    // Proceed with the original plaintext
} else {
    // Handle the decryption error
}

图片解密

从图片中解密数据并返回原始明文。

参数

  • $fileData (字符串):图片数据或文件路径。
  • $key (字符串,可选):解密密钥。默认为 "welovenfts"。
  • $datatype (字符串,可选):数据类型,可以是 "web" 或 "json"。

返回值

  • (字符串|数组):如果解密失败则返回错误信息或原始明文。

示例用法

require_once 'vendor/autoload.php';
use encrypted_images_php\decryption\images;

// Initialize the class
$imageDecryptor = new images();

// Decrypt data from an image
$decryptedText = $imageDecryptor->decryptFromImage($imageData, 'decryption-key', 'web');

if (!is_string($decryptedText)) {
    // Proceed with the original plaintext
} else {
    // Handle the decryption error
}