thihaeung/keylibrary

keylibrary

1.0 2024-04-16 19:56 UTC

This package is auto-updated.

Last update: 2024-09-16 20:54:48 UTC


README

RSA Logo

描述

在这个包中,您可以轻松地将rsa公钥和私钥存储在您喜欢的模型中,带有或没有集合:功能包括存储、获取、删除。我将通过示例向您展示。见下文,

设置

通过命令安装包

composer require thihaeung/keylibrary

发布密钥表 & 配置

  php artisan vendor:publish --provider="Thihaeung\KeyLibrary\Providers\KeyServiceProvider" --tag=key-library-config --tag=key-migrations

迁移表

php artisan migrate

用法

公钥扩展

  • crt,pem,pub,key

私钥扩展

  • crt,pem,key

在您的模型中使用密钥特性

use Thihaeung\KeyLibrary\Traits\HasKeyCollection;

use HasKeyCollection;

使用集合或不使用集合存储密钥。注意 - 如果您不添加集合,默认集合将是'keys'文件夹,密钥文件扩展名为.pem。

  • 不使用集合
$model->addToKeyCollection($publicKey, $privateKey);
  • 使用集合
$model->addToKeyCollection($publicKey, $privateKey, $collectionName);

获取密钥字符串和密钥路径

  • 不使用集合获取两个密钥。
$model->getKeys();
  • 使用集合获取两个密钥
$model->getKeys($collectionName);
  • 不使用集合获取公钥
$model->getPublicKey();
  • 使用集合获取公钥
$model->getPublicKey($collectionName);
  • 不使用集合获取私钥
$model->getPrivateKey();
  • 使用集合获取私钥
$model->getPrivateKey($collectionName);
  • 从所有集合中获取密钥
$model->getAllCollectionKeys();

删除密钥

  • 不使用集合删除密钥
$model->deleteKeyFromCollection();
  • 使用集合删除密钥
$model->deleteKeyFromCollection($collectionName);
  • 删除集合命令
php artisan key:delete-collection collectionName