virge/enigma

该包的最新版本(v2.0.0)没有可用的许可信息。

v2.0.0 2018-02-27 22:05 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:36:48 UTC


README

用于加密/解密数据和生成哈希值。

加密

加密使用mcrypt进行加密/解密数据。默认设置为RIJNDAEL_128,但可以根据需要更改。

$myString = "secrets";
$key = "password";
$encrypted = Enigma::encrypt($myString, $key);
Enigma::decrypt($encrypted, $key); //secrets

哈希

哈希使用hash_hmac函数,支持hash_algos()返回的所有算法;

$passwordHash = Enigma::hash('mypassword', 'salt');

也可以不输入内容使用,此时将生成当前微时间的哈希值

$randomhash = Enigma::hash();

加密文件

加密文件时,将输入文件和输出文件作为输入。输入文件以1MB的块读取,加密后写入输出文件。

同样,解密将读取输入文件(加密文件)和输出文件,逐行读取加密文件。

$inputFile = "./test.txt";

$outputFile = "./encrypted.txt";

$decryptedFile = "./decrypted.txt";

Enigma::encryptFile($inputFile, $outputFile, "secret");

Enigma::decryptFile($outputFile, $decryptedFile, "secret");

if(Enigma::md5File($inputFile) !== Enigma::md5File($decryptedFile)) {
    die("File hashes do not match");
}