ride/lib-encryption

Ride框架的加密库

1.1.0 2018-04-04 10:44 UTC

This package is auto-updated.

Last update: 2024-09-13 00:32:35 UTC


README

PHP Ride框架的加密库。

库中包含的内容

加密器

加密器接口用于实现加密器,使用加密密钥来加密和解密数据。

可用实现

  • ride\library\encryption\cipher\ChainCipher: 具有一定迭代次数的加密器链
  • ride\library\encryption\cipher\GenericCipher: 通用实现
  • ride\library\encryption\cipher\SimpleCipher: 简单实现,加密数据长度相对较短,不适用于敏感数据

哈希

哈希接口用于实现加密哈希算法。这些方法接受任意数据块并返回固定大小的位字符串

可用实现

  • ride\library\encryption\hash\GenericHash: 使用已安装的哈希函数,默认为SHA256
  • ride\library\encryption\hash\PlainHash: 用于测试目的

代码示例

查看此代码示例以了解此库的功能

<?php

use ride\library\encryption\cipher\GenericCipher;
use ride\library\encryption\exception\EncryptionException;
use ride\library\encryption\hash\GenericHash;

// cipher to encrypt and decrypt data
try {
    $cipher = new GenericCiper();
    $data = "Top secret mission";
    
    // if you don't have a secret key, you can generate one
    $key = $cipher->generateKey();
    
    $encrypted = $cipher->encrypt($data, $key);
    $decrypted = $cipher->decrypt($encrypted, $key); 
} catch (EncryptionException $exception) {
    // something's up!
}

// hash to generate a code of fixed size, good for passwords
$hash = new GenericHash();
$data = $hash->hash($data); 

安装

您可以使用Composer来安装此库。

composer require ride/lib-encryption