arzzen/php-time-lock-encryption

时间锁加密类

1.1.0 2015-09-09 18:58 UTC

This package is auto-updated.

Last update: 2024-09-09 18:13:10 UTC


README

定时发布加密的实现。

此类可以使用为特定时间段生成的密钥来加密数据。

它通过在循环中迭代性地创建初始密钥的哈希值,直到指定的时间过去,来生成密钥。

该类使用生成的密钥通过Fernet类返回加密数据。

它还可以通过以与加密数据时生成密钥相同的迭代次数重新生成加密密钥来解密之前加密的数据。

要求

  • PHP 5.3.3 或更高版本
  • hash 扩展
  • openssl 或 mcrypt 扩展

安装

您可以使用 [Composer] 安装此库。您也可以在 [Packagist] 上查看更多信息。

将此添加到您的 composer.json 文件中的 require 部分。

{
    "require": {
        "arzzen/php-time-lock-encryption": "1.1.*"
    }
}

用法

<?php
use TimeLockCrypt;

$timeLock = new TimeLockCrypt('keyseed');

$message = 'secret message';
$encrypted = $timeLock->encrypt('+10 second', $message);
$iterations = $timeLock->getIterations();

$decrypted = $timeLock->decrypt($encrypted, $iterations);

var_dump($message == $decrypted);
?>