PHP code example of petalbranch / petal-cipher
1. Go to this page and download the library: Download petalbranch/petal-cipher 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/ */
petalbranch / petal-cipher example snippets
use Petalbranch\PetalCipher\Utils;
// 引入文件
use Petalbranch\PetalCipher\PetalCipher; // 引入 PetalCipher 类
$pc = new PetalCipher('your_seed'); // 创建 PetalCipher 实例并传入种子
$encrypted = $pc->encrypt('your_data'); // 加密您的数据
$decrypted = $pc->decrypt($encrypted); // 解密您的数据
echo $pc->getSeed(); // 获取您设置的种子
$pc->updateSeed('your_new_seed'); // 更新种子
$encrypted = $pc->encrypt('your_data'); // 使用新的种子加密数据
$decrypted = $pc->decrypt($encrypted); // 使用新的种子解密数据
$pc->customDict("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"); // 自定义字典
$encrypted = $pc->encrypt('your_data'); // 使用新的种子加密数据
$decrypted = $pc->decrypt($encrypted); // 使用新的种子解密数据
// 默认种子 方式1
$encrypted = petal_encrypt('your_data'); // 加密您的数据
$decrypted = petal_decrypt($encrypted); // 解密您的数据
// 默认种子 方式2 (和方式1一样,但是没必要这么写)
$seed = petal_seed();
$encrypted = petal_encrypt('your_data',$seed); // 加密您的数据
$decrypted = petal_decrypt($encrypted,$seed); // 解密您的数据
// 自定义种子
$seed = petal_seed('your_seed'); // 设置种子
$encrypted = petal_encrypt('your_data',$seed); // 加密您的数据
$decrypted = petal_decrypt($encrypted,$seed); // 解密您的数据
// 自定义字典
$seed = petal_custom_dict("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/");
$encrypted = petal_encrypt('your_data',$seed); // 加密您的数据
$decrypted = petal_decrypt($encrypted,$seed); // 解密您的数据
$pc = new PetalCipher();
$encrypt = $pc->encrypt('hello world');
echo "E1: ".$encrypt."\n";
$decrypt = $pc->decrypt($encrypt);
echo "D1: ".$decrypt."\n";
$encrypt = $pc->encrypt('hello world');
echo "E2: ".$encrypt."\n";
$decrypt = $pc->decrypt($encrypt);
echo "D2: ".$decrypt."\n";
// 功能测试
56");
$string = "hello, world.";
$encrypt = petal_encrypt($string, $seed);
$decypt = petal_decrypt($encrypt, $seed);
echo "PV: " . phpversion() . "\n";
echo "O: " . $string . "\n";
echo "E: " . $encrypt . "\n";
echo "D: " . $decypt . "\n";
// 跨PHP版本兼容性测试
��前PV
echo "PV: " . phpversion() . "\n";
// 以下数据由 PV: 7.4.9 生成
echo petal_decrypt("Ye0HcyePXHa/nj+B49x3cU==", $seed) . "\n";
echo petal_decrypt("02bKcp2NXKuZ6KtdsrHjey==", $seed) . "\n";
echo petal_decrypt("x+Huch+G5ujzX2Sew8a1lN==", $seed) . "\n";
echo petal_decrypt("4as/c+a7X/DPCljxXgw9zl==", $seed) . "\n";
echo petal_decrypt("DAo4JcAHr4FDN4zjfprL1b==", $seed) . "\n";
echo petal_decrypt("ZEXTc3EoCTmSbH9FQBiOLv==", $seed) . "\n";
echo petal_decrypt("WiCUJEiMrUP51hmZbYQtkL==", $seed) . "\n";
echo petal_decrypt("x+Huch+G5ujCXISew8a1lN==", $seed) . "\n";
echo petal_decrypt("PgNWJ8gXCWd/vLkm7aGeO6==", $seed) . "\n";
echo petal_decrypt("suIvctu5XvoJJkYHqZ/ra+==", $seed) . "\n";
echo petal_decrypt("HtK7JOtWD7YlqLB2/FuA+h==", $seed) . "\n";
echo petal_decrypt("AlxaJNltCa3DZf5cF6zVKP==", $seed) . "\n";
bash
PS D:\develop\test\test_petalcipher> php index.php
PV: 8.3.17
O: hello, world.
E: I7z3JG7Sr3VPkS0KLXv4ut==
D: hello, world.
bash
PS D:\develop\test\test_petalcipher> D:\develop\devenv\php\php7.4.9nts\php.exe index.php
PV: 7.4.9
O: hello, world.
E: 4as/c+a7X/DPC8jxXgw9zl==
D: hello, world.
bash
PS D:\develop\test\test_petalcipher> D:\develop\devenv\php\php7.4.9nts\php.exe index.php
PV: 8.3.17
hello, world.
hello, world.
hello, world.
hello, world.
hello, world.
hello, world.
hello, world.
hello, world.
hello, world.
hello, world.
hello, world.
hello, world.
bash
PS D:\develop\test\test_petalcipher> D:\develop\devenv\php\php7.4.9nts\php.exe index.php
PV: 7.4.9
hello, world.
hello, world.
hello, world.
hello, world.
hello, world.
hello, world.
hello, world.
hello, world.
hello, world.
hello, world.
hello, world.
hello, world.