定制 wutif/crittora-sdk-php 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

wutif/crittora-sdk-php

最新稳定版本:v1.0.11

Composer 安装命令:

composer require wutif/crittora-sdk-php

包简介

Crittora SDK for PHP

README 文档

README

The Crittora SDK for PHP provides a simple interface for authentication, encryption, and decryption of data using the Crittora API. This document will guide you through the setup and usage of the SDK, as well as running the demo application.

Table of Contents

Installation

To install the Crittora SDK, you need to have Composer installed. Run the following command to install the dependencies:

composer require wutif/crittora-sdk-php

Demo Application

The simplest way to get started with Crittora is to view a demo. The demo application provides a simple interface to test the authentication, encryption, and decryption functionalities of the SDK.

https://github.com/Crittora/crittora-demo-php

Features

  • User authentication using environment variables.
  • Data encryption and decryption.
  • User-friendly web interface built with Bootstrap.
Requirements
  • PHP 7.2 or higher
  • Composer
  • Access to the Crittora SDK

Usage

Initialize SDK

Initialize the SDK by passing in your accessKey and secretKey. This will return the IdToken which you will need to use when calling the encrypt and decrypt methods

use Crittora\CrittoraSDK;

$sdk = new CrittoraSDK($accessKey, $secretKey);

Example

try {
    $sdk = new CrittoraSDK($accessKey, $secretKey);
    $authResponse = $sdk->authenticate($username, $password);
    echo json_encode(['success' => true, 'IdToken' => $authResponse['IdToken']]);
} catch (Exception $e) {
    http_response_code(401);
    echo json_encode(['success' => false, 'error' => $e->getMessage()]);
}

Authentication

To authenticate a user, use the authenticate method of the CrittoraSDK class. This method requires a username and password and returns an array containing tokens.

$authResponse = $sdk->authenticate('username', 'password');

Encryption

To encrypt data, use the encrypt method. This method requires an ID token, the data to encrypt, and an optional array of permissions.

$encryptedData = $sdk->encrypt($idToken, 'data to encrypt', ['read', 'write']);

Decryption

To decrypt data, use the decrypt method. This method requires an ID token, the encrypted data, and an optional array of permissions.

$decryptedData = $sdk->decrypt($idToken, $encryptedData, ['read']);

Testing

To run the tests, use PHPUnit. Ensure you have PHPUnit installed and configured. Run the following command in the root directory:

  vendor/bin/phpunit

Contributing

Contributions are welcome! Please fork the repository and submit a pull request for any improvements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

统计信息

  • 总下载量: 24
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-20