PHP code example of swordying / crypter
1. Go to this page and download the library: Download swordying/crypter 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/ */
swordying / crypter example snippets
## 引入类文件
�认 AES-256-GCM)
$crypter = new \Swordying\Crypter();
## 明文
$ho = 'Hello World!';
## 加密后的值(包含 iv + tag + ciphertext 的 base64 串)
$en = $crypter -> handle($ho);
## 散列值(用于数据库等值查询)
$md = $crypter -> md($ho);
## 解密后的值
$de = $crypter -> de($en['en']);
var_export($ho);
echo "\n";
var_export($en);
echo "\n";
var_export($md);
echo "\n";
var_export($de);
$crypter = new \Swordying\Crypter([
## 加密方法:AES-128-GCM | AES-256-GCM(默认)
'method' => 'AES-256-GCM',
## 密钥(字符串,不传则从 key_file 读取)
## 注意:AES-128-GCM 需要 16 字节,AES-256-GCM 需要 32 字节
## 不足自动以 \0 填充,超出自动截断
'key' => '',
## 密钥文件路径(默认 ./src/aes.key)
'key_file' => __DIR__.'/aes.key',
## 散列盐值
'salt' => '#=#.salt.#=#',
]);
## 生成 AES-256-GCM 密钥(32 字节),默认写入 ./src/aes.key
$key256 = \Swordying\Crypter::createKey();
var_export($key256); ## 十六进制字符串
## 生成 AES-128-GCM 密钥(16 字节)
$key128 = \Swordying\Crypter::createKey('AES-128-GCM');
var_export($key128);
## 指定保存路径
\Swordying\Crypter::createKey('AES-256-GCM', '/path/to/your.key');