wutif/crittora-sdk-php

Crittora SDK for PHP

v1.0.11 2024-12-23 17:03 UTC

This package is auto-updated.

Last update: 2025-05-23 17:47:59 UTC


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.