https://github.com/krakphp/crypto
Cryptographic Library
https://github.com/krakphp/crypto
Last synced: about 1 year ago
JSON representation
Cryptographic Library
- Host: GitHub
- URL: https://github.com/krakphp/crypto
- Owner: krakphp
- License: mit
- Created: 2016-04-25T22:43:42.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-04-20T00:25:25.000Z (about 9 years ago)
- Last Synced: 2025-03-02T03:58:23.147Z (over 1 year ago)
- Language: PHP
- Size: 29.3 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
```