nsp-team/crypt-tool

1.0.0 2021-11-10 07:18 UTC

This package is auto-updated.

Last update: 2024-09-10 13:50:42 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License PHP Version Require

摘要

crypt包为phpseclib AES-128库创建了一个简单的接口。它的接口允许使用base64编码层对字符串进行加密和解密,以便于传输,包括初始化向量。

安装

composer require nsp-team/crypt-tool:~1.0.0

使用方法

在使用此库之前,您需要选择一个密钥,其大小只能是16、24或32位。

<?php

use NspTeam\Crypt\Crypt;

$secretKey = "1234567890123456";

//1. Encrypt and Encode plain text data for storage or transmission 
$encodedEncryptedData = (new Crypt($secretKey))->encrypt("message");

//2. Decoding and Decrypting stored or received data
$encodedEncryptedData = (new Crypt($secretKey))->decrypt("encoded_encrypted_data");

//3. Encrypting and Decrypting with an alternate length initialization vector

$crypt = new Crypt($secretKey);

$alternateIVLength = 8;
$encodedEncryptedData = $crypt->encrypt("message", $alternateIVLength);
$plainText = $crypt->decrypt($encodedEncryptedData, $alternateIVLength);

当传入错误数据时,方法调用 CrowdStar\Crypt\Crypt::decrypt() 的返回值将是一个空字符串。

PhpUnit

php phpunit.phar --bootstrap tests/bootstrap.php tests/CryptTest.php