ammarfaizi2/teacrypt

v1.4 2017-06-02 04:27 UTC

This package is not auto-updated.

Last update: 2024-09-15 02:11:38 UTC


README

加密解决方案

Teacrypt 的优势

  • 使用盐进行加密过程。因此,即使使用相同的密钥,加密结果也总是不同的。
  • 加密结果将使用 gzdeflate 进行压缩。
  • 压缩结果将使用 base64 编码。因此,最终返回的结果总是可打印的。
  • 如果使用相同的密钥进行解密,解密结果总是与原始数据相同。

示例

<?php
require __DIR__ . '/vendor/autoload.php';
use Teacrypt\Teacrypt;

$string = "hello world";
$key    = "redangel";
$encrypted_string1 = Teacrypt::encrypt($string, $key);
$decrypted_string2 = Teacrypt::decrypt($encrypted_string1, $key);

$encrypted_string2 = Teacrypt::encrypt($string, $key);
$decrypted_string2 = Teacrypt::decrypt($encrypted_string2, $key);

var_dump(array(
        "hasil kesamaan enkripsi 1 dan 2" => ($encrypted_string1 == $encrypted_string2),
        "encrypted_string" => array($encrypted_string1, $encrypted_string2),
        "decrypted_string" => array($decrypted_string2, $decrypted_string2)
    ));

将会生成

array(3) {
  ["hasil kesamaan enkripsi 1 dan 2"]=>
  bool(false)
  ["encrypted_string"]=>
  array(2) {
    [0]=>
    string(24) "LikCOgUyUFLUmnwMlHXlmLAA"
    [1]=>
    string(24) "rUjyKKDi3WLS3zadlPndULAA"
  }
  ["decrypted_string"]=>
  array(2) {
    [0]=>
    string(11) "hello world"
    [1]=>
    string(11) "hello world"
  }
}

安装

添加 composer.json

{
	"require": {
		"ammarfaizi2/teacrypt": "1.4"
	}
}