An open API service indexing awesome lists of open source software.

https://github.com/byjg/php-crypto

A generic repository for implement cryptographic algorithms with a customizable strong key generator.
https://github.com/byjg/php-crypto

Last synced: 6 months ago
JSON representation

A generic repository for implement cryptographic algorithms with a customizable strong key generator.

Awesome Lists containing this project

README

          

# Crypto

[![Build Status](https://github.com/byjg/php-crypto/actions/workflows/phpunit.yml/badge.svg?branch=master)](https://github.com/byjg/php-crypto/actions/workflows/phpunit.yml)
[![Opensource ByJG](https://img.shields.io/badge/opensource-byjg-success.svg)](http://opensource.byjg.com)
[![GitHub source](https://img.shields.io/badge/Github-source-informational?logo=github)](https://github.com/byjg/php-crypto/)
[![GitHub license](https://img.shields.io/github/license/byjg/php-crypto.svg)](https://opensource.byjg.com/opensource/licensing.html)
[![GitHub release](https://img.shields.io/github/release/byjg/php-crypto.svg)](https://github.com/byjg/php-crypto/releases/)

A "passwordless" cryptography library for symmetric encryption.

## How it works?

The algorithm is well-know, but the major problem is HOW to store the symmetric key. Instead of store the key,
this library use a key seed, and it is able to generate the key dynamically for each encrypting based
on a key seed. The key seed is a list of 32 lines of 32 bytes each.

## Usage

```php
encrypt($text);
echo $object->decrypt($encrypted);
```

- The algorithm needs to be one of the algorithms returned by `openssl_get_cipher_methods()`.
- The second parameter is the key seed. It is a list of 2-255 entries of 32 bytes each. You can generate it using the command
`BaseCrypto::getKeySet()`

## Example

Below a full example:

```php
encrypt('My secret text needs to be encrypted');
echo $object->decrypt($enc) . "\n";
```

**Important**

- Do not share the key seed.
- You'll only be able to decrypt the text if you have the same key seed used to encrypt it.

## Additional Documentation

- [Advanced uses of KeySet class](docs/advanced-uses-keyset.md)
- [Interoperability with JavaScript](docs/interoperability.md)

## Installation

```
composer require "byjg/crypto"
```

## Running the tests

```
./vendor/bin/phpunit
```

## Dependencies

```mermaid
flowchart TD
byjg/crypto --> ext-openssl
```

----
[Open source ByJG](http://opensource.byjg.com)