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

https://github.com/krakphp/crypto

Cryptographic Library
https://github.com/krakphp/crypto

Last synced: about 1 year ago
JSON representation

Cryptographic Library

Awesome Lists containing this project

README

          

# Crypto

A well designed cryptographic library for php.

## Install

```
composer require krak/crypto
```

## Design

The Crypto Library has two main interfaces: `Crypt` and `Pad`.

A Crypt is what does the encryption and decryption.

A Pad is what does the padding and stripping.

## Usage

```php
encrypt('data');
echo $crypt->decrypt($encrypted);
// outputs: data
```

All Crypts implement the interface `Krak\Crypto\Crypt`

You can also use any of the `Krak\Crypto\Pad` classes

```php
pad('abc');
echo $pad->strip($padded);
// outputs: abc
```

### Crypt

The Crypt libraries are responsible for encrypting the data. There are crypt implementations that do encryption and others that are just decorators.

**McryptCrypt** and **OpenSSLCrypt** handle encryption. Each crypt uses the `Krak\Crypto\pack_payload` method to prepend the iv to the cipher text.

**Note:** Please be knowledgeable of the keys you pass in. The key size depends on the algorithm and typically ranges from 8, 16, 24, or 32 bytes.

**Base64Crypt**, **HmacCrypt**, and are decorators for providing base64 encoding and hmac signing/authentication for your messages.

**GnuPGCliCrypt** handles encrypting via the `gpg` cli utility.

```php
pipe(Crypto\map_stream('strtoupper'))
->pipe($crypt_stream->encrypt())
->pipe($base64_stream->encode())
->pipe(Crypt\write_stream($dst));
// at this point, stdout will have encrypted uppercased info.
```

Look at the API to see all of the different streams and how to use them.

## API

Run `make api` to create the api documentation. Then open up `docs/api/index.html` to view the API docs.

## Test

Run tests with peridot via

```
make test
```