A PHP application for creating CMS (Cryptographic Message Syntax) packages using the GoodKey signing service.
- PHP 7.4 or higher
- Composer
- OpenSSL
On macOS:
# Install via Homebrew
brew install php
On Ubuntu/Debian:
# Install via apt
sudo apt update
sudo apt install php
composer install
Set required environment variables:
# GoodKey API URL
export API_URL="http://api.goodkey.pp.ua"
# GoodKey API Token
export API_TOKEN="gkt-01234567890abcdef"
To obtain the API token from the GoodKey server, follow these steps:
- Open GoodKey application at https://app.goodkey.pp.ua/
- Navigate to your organization page
- Go to
Access tokens
tab - Click
Create token
button - Fill in the required fields
- In the
Allowed keys
field, select a keyNote: The key must be RSA 2048 format, as the PHP server only implements RSA 2048 + SHA256
- In the
Allowed certificates
field, select the certificate associated with the key - Complete the creation by clicking
Create token
- Copy the token value and use it as your
API_TOKEN
Start the development server:
php -S localhost:8000 -t src
Run the included test script to verify functionality:
bash test-cli.sh
The test script:
- Creates a test file (
test.txt
) - Calculates SHA-256 hash
- Generates CMS signature
- Saves signature to
signature.cms
- Verifies signature using OpenSSL
Here's a simple example demonstrating how to use the application classes to create a CMS signature:
<?php
require 'vendor/autoload.php';
use Peculiarventures\GoodkeyCms\ApiClient;
use Peculiarventures\GoodkeyCms\CmsBuilder;
// Create client and CMS builder
$client = new ApiClient(
getenv('API_URL'),
getenv('API_TOKEN')
);
$builder = new CmsBuilder($client);
// Example data to sign
$data = 'This is a test message.';
$hash = hash('sha256', $data);
// Create CMS signature
$cms = $builder->create($hash);
// Return signed data
header('Content-Type: application/octet-stream');
echo $cms;
This script initializes the ApiClient
and CmsBuilder
classes, creates a SHA-256 hash of the data, generates a CMS signature, and returns the signed data.