Skip to content

Commit

Permalink
First version
Browse files Browse the repository at this point in the history
  • Loading branch information
SiViN committed Apr 30, 2019
1 parent 60b7386 commit 67363ae
Show file tree
Hide file tree
Showing 15 changed files with 733 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# IDE
/.idea

# Composer
/vendor
/composer.lock
24 changes: 24 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
language: php
php:
- 7.1
- 7.2
- 7.3

env:
- PHP_BIN=php
- PHP_BIN=php-cgi

before_install:
- phpenv config-rm xdebug.ini || return 0 # Turn off XDebug

install:
- travis_retry composer install # Composer

script:
- vendor/bin/tester -p $PHP_BIN tests -s # Tests

sudo: false

cache:
directories:
- $HOME/.composer/cache
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# crypt
Small library for encryption via [phpseclib](https://github.com/phpseclib/phpseclib)

[![Build Status](https://travis-ci.org/SiViN/crypt.svg?branch=master)](https://travis-ci.org/SiViN/crypt)
[![License](https://poser.pugx.org/sivin/crypt/license)](https://packagist.org/packages/sivin/crypt)
[![Total Downloads](https://poser.pugx.org/sivin/crypt/downloads)](https://packagist.org/packages/sivin/crypt)

1. Install via composer
```yaml
composer require sivin/crypt
```

2. Register extension in `config.neon`:
```php
extensions:
crypt: SiViN\Crypt\DI\CryptExtension
```

3. Create or use your key/s:
```php
/** @var Crypt */
private $crypt;

public function __construct(Crypt $crypt)
{
$this->crypt = $crypt;
}
...
$keys = $this->crypt->createKeyPair()
$privateKeyRaw = $keys['privateKeyRaw'];
$publicKeyRaw = $keys['publicKeyRaw'];
```

4. Use your own key or define it in a `config.local.neon`:
```php
$crypt->setPublicKey($myPublicKeyForEncrypt);
$crypt->setPrivateKey($myPrivateKeyForDecrypt);
//if there is a private key with a password
$crypt->setPrivateKeyPassword($myPivateKeyPasswordForDecrypt);
```

or in a `config.local.neon`:

```php
crypt:
publicKeyPath: publicKeyFile.pub #for encrypting
privateKeyPath: privateKeyFile.key #for decrypting
privateKeyPassword: 'PrivateKeyPassword' #optional
```
>If you only want to encrypt/decrypt, just define the encrypting/decrypting key

5. And finally?:
```php
$encryptedStr = $crypt->encryptRijndaelMessage($stringToEncode); //for transport
$decryptedStr = $crypt->decryptRijndaelMessage($encryptedStr);

$encryptedStr = $crypt->encryptRsa($stringToEncode);
$decryptedStr = $crypt->decryptRsa($encryptedStr);

$encryptedStr = $crypt->encryptRijndael($stringToEncode);
$decryptedStr = $crypt->decryptRijndael($encryptedStr);
```


50 changes: 50 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "sivin/crypt",
"type": "library",
"description": "Small library for encryption via phpseclib",
"keywords": [
"security",
"crypt",
"nette",
"rsa",
"aes",
"blowfish",
"twofish",
"ssh",
"sftp",
"x509",
"x.509",
"asn1",
"asn.1",
"BigInteger"
],
"require": {
"php": ">= 7.1",
"ext-openssl": "*",
"phpseclib/phpseclib": "^2.0",
"nette/di": "^2.4",
"tracy/tracy": "^2.6"
},
"require-dev": {
"ninjify/nunjuck": "^0.3.0@dev"
},
"license": "MIT",
"authors": [
{
"name": "Milan Sivak",
"email": "sivin@atlas.cz"
}
],
"autoload": {
"psr-4": {
"SiViN\\Crypt\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"SiViN\\Crypt\\Tests\\": "tests"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
Loading

0 comments on commit 67363ae

Please sign in to comment.