Skip to content

Commit 438932f

Browse files
Merge pull request #2 from VirgilSecurity/dev
Add new SeqCipher functionality
2 parents 204e1c4 + f38f5cd commit 438932f

File tree

15 files changed

+587
-41
lines changed

15 files changed

+587
-41
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
vendor/
44
samples/
55
composer.lock
6+
/tests/src/decr_test.pdf
7+
/tests/src/test.enc

.travis.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
language: php
2+
matrix:
3+
include:
4+
- os: linux
5+
compiler: gcc
6+
env: PHPUNIT_VERSION=6.2 PHP_VERSION=7.2
7+
sudo: required
8+
dist: trusty
9+
before_install:
10+
- date -u
11+
- uname -a
12+
- if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then lscpu; fi
13+
install:
14+
# Use clean dependencies installation to avoid versions collision.
15+
- export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
16+
- echo "Install PHP version ${PHP_VERSION} ..."
17+
- travis_retry sudo apt-add-repository -y ppa:ondrej/php
18+
- travis_retry sudo apt-get -qq update
19+
- travis_retry sudo apt-get install -y -qq php${PHP_VERSION}
20+
- travis_retry sudo apt-get install -y -qq php${PHP_VERSION}-cli
21+
- travis_retry sudo apt-get install -y -qq php${PHP_VERSION}-dev
22+
- travis_retry sudo apt-get install -y -qq php${PHP_VERSION}-mbstring
23+
- travis_retry sudo apt-get install -y -qq php${PHP_VERSION}-curl
24+
- echo "Install PHPUnit version ${PHPUNIT_VERSION} ..."
25+
- travis_retry wget https://phar.phpunit.de/phpunit-${PHPUNIT_VERSION}.phar
26+
- chmod +x phpunit-${PHPUNIT_VERSION}.phar
27+
- sudo mv phpunit-${PHPUNIT_VERSION}.phar /usr/bin/phpunit
28+
- echo "Install composer globally"
29+
- curl -sS https://getcomposer.org/installer -o composer-setup.php
30+
- sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
31+
- php --version
32+
- php -i
33+
- phpunit --version
34+
- php-config --extension-dir
35+
- composer --version
36+
before_script:
37+
- sudo cp $TRAVIS_BUILD_DIR/build/virgil_crypto_php.so /usr/lib/php/20170718
38+
- cd /usr/lib/php/20170718
39+
- ls -a
40+
- sudo sh -c "echo 'extension=virgil_crypto_php.so' >> /etc/php/7.2/cli/php.ini"
41+
- cd $TRAVIS_BUILD_DIR
42+
- composer install
43+
script: phpunit --configuration phpunit.xml --coverage-text

README.md

Lines changed: 94 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,110 @@
1-
## Native Virgil Crypto Library
1+
# Virgil Security PHP Crypto Library
22

3-
Package implements virgil/crypto-api interfaces.
3+
[![Build Status](https://api.travis-ci.com/VirgilSecurity/crypto-php.svg?branch=master)](https://travis-ci.com/VirgilSecurity/crypto-php/)
44

5-
## Requirements
5+
[![GitHub license](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg)](https://github.com/VirgilSecurity/virgil/blob/master/LICENSE)
66

7-
* PHP 5.6+
8-
* virgil/crypto-api
9-
* virgil_crypto_php.so extension
7+
### [Introduction](#introduction) | [Library purposes](#library-purposes) | [Usage examples](#usage-examples) | [Installation](#installation) | [Docs](#docs) | [License](#license) | [Contacts](#support)
8+
9+
## Introduction
10+
VirgilCrypto is a stack of security libraries (ECIES with Crypto Agility wrapped in Virgil Cryptogram) and an open-source high-level [cryptographic library](https://github.com/VirgilSecurity/virgil-crypto) that allows you to perform all necessary operations for securely storing and transferring data in your digital solutions. Crypto Library is written in C++ and is suitable for mobile and server platforms.
11+
12+
Virgil Security, Inc., guides software developers into the forthcoming security world in which everything will be encrypted (and passwords will be eliminated). In this world, the days of developers having to raise millions of dollars to build a secure chat, secure email, secure file-sharing, or a secure anything have come to an end. Now developers can instead focus on building features that give them a competitive market advantage while end-users can enjoy the privacy and security they increasingly demand.
13+
14+
## Library purposes
15+
* Asymmetric Key Generation
16+
* Encryption/Decryption of data and streams
17+
* Generation/Verification of digital signatures
18+
* PFS (Perfect Forward Secrecy)
19+
20+
## Usage examples
21+
22+
#### Generate a key pair
23+
24+
Generate a Private Key with the default algorithm (EC_X25519):
25+
```php
26+
use Virgil\CryptoImpl\VirgilCrypto;
27+
28+
$crypto = new VirgilCrypto();
29+
$keyPair = $crypto->generateKeys();
30+
```
31+
32+
#### Generate and verify a signature
33+
34+
Generate signature and sign data with a private key:
35+
```php
36+
use Virgil\CryptoImpl\VirgilCrypto;
37+
38+
$crypto = new VirgilCrypto();
39+
40+
// prepare a message
41+
$messageToSign = "Hello, Bob!";
42+
43+
// generate a signature
44+
$signature = $crypto->generateSignature($messageToSign, $senderPrivateKey);
45+
```
46+
47+
Verify a signature with a public key:
48+
```php
49+
use Virgil\CryptoImpl\VirgilCrypto;
50+
51+
$crypto = new VirgilCrypto();
52+
53+
// verify a signature
54+
$crypto->verifySignature($signature, $dataToSign, $senderPublicKey);
55+
```
56+
#### Encrypt and decrypt data
57+
58+
Encrypt Data on a Public Key:
59+
60+
```php
61+
use Virgil\CryptoImpl\VirgilCrypto;
62+
63+
$crypto = new VirgilCrypto();
64+
65+
// prepare a message
66+
$messageToEncrypt = "Hello, Bob!";
67+
68+
// encrypt the message
69+
$encryptedData = $crypto->encrypt($messageToEncrypt, $receiverPublicKey);
70+
```
71+
Decrypt the encrypted data with a Private Key:
72+
```php
73+
use Virgil\CryptoImpl\VirgilCrypto;
74+
75+
$crypto = new VirgilCrypto();
76+
77+
// prepare data to be decrypted
78+
$decryptedData = $crypto->decrypt($encryptedData, $receiverPrivateKey);
79+
```
80+
Need more examples? Visit our [developer documentation](https://developer.virgilsecurity.com/docs/how-to#cryptography).
1081

1182
## Installation
1283

84+
### Requirements
85+
86+
* PHP 5.6 and newer
87+
* virgil_crypto_php extension
88+
89+
You can download virgil_crypto_php extension from our [CDN](https://cdn.virgilsecurity.com/virgil-crypto/php/).
90+
91+
### Installation via composer
92+
1393
```bash
1494
composer require virgil/crypto
1595
```
1696

17-
## License
18-
19-
BSD 3-Clause. See LICENSE for details.
97+
## Docs
98+
- [Crypto Core Library](https://github.com/VirgilSecurity/virgil-crypto)
99+
- [More usage examples](https://developer.virgilsecurity.com/docs/how-to#cryptography)
20100

21-
## Virgil Crypto V4
22-
23-
https://github.com/VirgilSecurity/virgil-sdk-crypto-php/tree/v4
101+
## License
24102

25-
## Contacts
103+
This library is released under the [3-clause BSD License](LICENSE).
26104

27-
Our developer support team is here to help you. Find out more information on our [Help Center](https://help.virgilsecurity.com/).
105+
## Support
106+
Our developer support team is here to help you.
28107

29108
You can find us on [Twitter](https://twitter.com/VirgilSecurity) or send us email [email protected].
30109

31-
Also, get extra help from our support team on [Slack](https://virgilsecurity.slack.com/join/shared_invite/enQtMjg4MDE4ODM3ODA4LTc2OWQwOTQ3YjNhNTQ0ZjJiZDc2NjkzYjYxNTI0YzhmNTY2ZDliMGJjYWQ5YmZiOGU5ZWEzNmJiMWZhYWVmYTM).
110+
Also, get extra help from our support team on [Slack](https://join.slack.com/t/VirgilSecurity/shared_invite/enQtMjg4MDE4ODM3ODA4LTc2OWQwOTQ3YjNhNTQ0ZjJiZDc2NjkzYjYxNTI0YzhmNTY2ZDliMGJjYWQ5YmZiOGU5ZWEzNmJiMWZhYWVmYTM).
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?php
2+
/**
3+
* Copyright (C) 2015-2018 Virgil Security Inc.
4+
*
5+
* All rights reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are
9+
* met:
10+
*
11+
* (1) Redistributions of source code must retain the above copyright
12+
* notice, this list of conditions and the following disclaimer.
13+
*
14+
* (2) Redistributions in binary form must reproduce the above copyright
15+
* notice, this list of conditions and the following disclaimer in
16+
* the documentation and/or other materials provided with the
17+
* distribution.
18+
*
19+
* (3) Neither the name of the copyright holder nor the names of its
20+
* contributors may be used to endorse or promote products derived from
21+
* this software without specific prior written permission.
22+
*
23+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
24+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26+
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33+
* POSSIBILITY OF SUCH DAMAGE.
34+
*
35+
* Lead Maintainer: Virgil Security Inc. <[email protected]>
36+
*/
37+
38+
namespace Virgil\CryptoImpl\Cryptography\Cipher;
39+
40+
use Exception;
41+
use Virgil\CryptoImpl\Cryptography\Exceptions\SeqCipherException;
42+
use Virgil\CryptoImpl\VirgilPrivateKey;
43+
44+
/**
45+
* Class VirgilSeqCipher
46+
* @package Virgil\CryptoImpl\Cryptography\Cipher
47+
*/
48+
class VirgilSeqCipher
49+
{
50+
/**
51+
* @var \VirgilSeqCipher
52+
*/
53+
private $cipher;
54+
55+
/**
56+
* VirgilSeqCipher constructor.
57+
*/
58+
public function __construct()
59+
{
60+
$this->cipher = new \VirgilSeqCipher();
61+
}
62+
63+
/**
64+
* @throws SeqCipherException
65+
*/
66+
public function startEncryption()
67+
{
68+
try {
69+
return $this->cipher->startEncryption();
70+
} catch (Exception $exception) {
71+
throw new SeqCipherException($exception->getMessage(), $exception->getCode());
72+
}
73+
}
74+
75+
/**
76+
* @param $data
77+
* @return mixed
78+
* @throws SeqCipherException
79+
*/
80+
public function process($data)
81+
{
82+
try {
83+
return $this->cipher->process($data);
84+
} catch (Exception $exception) {
85+
throw new SeqCipherException($exception->getMessage(), $exception->getCode());
86+
}
87+
}
88+
89+
/**
90+
* @return mixed
91+
* @throws SeqCipherException
92+
*/
93+
public function finish()
94+
{
95+
try {
96+
return $this->cipher->finish();
97+
} catch (Exception $exception) {
98+
throw new SeqCipherException($exception->getMessage(), $exception->getCode());
99+
}
100+
}
101+
102+
/**
103+
* @param $password
104+
*/
105+
public function addPasswordRecipient($password)
106+
{
107+
$this->cipher->addPasswordRecipient($password);
108+
}
109+
110+
/**
111+
* @param $password
112+
* @throws SeqCipherException
113+
*/
114+
public function startDecryptionWithPassword($password)
115+
{
116+
try {
117+
return $this->cipher->startDecryptionWithPassword($password);
118+
} catch (Exception $exception) {
119+
throw new SeqCipherException($exception->getMessage(), $exception->getCode());
120+
}
121+
}
122+
123+
/**
124+
* @param $recipientId
125+
* @param VirgilPrivateKey $privateKey
126+
* @throws SeqCipherException
127+
*/
128+
public function startDecryptionWithKey($recipientId, VirgilPrivateKey $privateKey)
129+
{
130+
try {
131+
return $this->cipher->startDecryptionWithKey($recipientId, $privateKey);
132+
} catch (Exception $exception) {
133+
throw new SeqCipherException($exception->getMessage(), $exception->getCode());
134+
}
135+
}
136+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright (C) 2015-2018 Virgil Security Inc.
4+
*
5+
* All rights reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are
9+
* met:
10+
*
11+
* (1) Redistributions of source code must retain the above copyright
12+
* notice, this list of conditions and the following disclaimer.
13+
*
14+
* (2) Redistributions in binary form must reproduce the above copyright
15+
* notice, this list of conditions and the following disclaimer in
16+
* the documentation and/or other materials provided with the
17+
* distribution.
18+
*
19+
* (3) Neither the name of the copyright holder nor the names of its
20+
* contributors may be used to endorse or promote products derived from
21+
* this software without specific prior written permission.
22+
*
23+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
24+
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26+
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
27+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32+
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33+
* POSSIBILITY OF SUCH DAMAGE.
34+
*
35+
* Lead Maintainer: Virgil Security Inc. <[email protected]>
36+
*/
37+
38+
namespace Virgil\CryptoImpl\Cryptography\Exceptions;
39+
40+
use Exception;
41+
42+
/**
43+
* Class SeqCipherException
44+
* @package Virgil\CryptoImpl\Cryptography\Exceptions
45+
*/
46+
class SeqCipherException extends Exception
47+
{
48+
49+
}

build/virgil_crypto_php.so

2.03 MB
Binary file not shown.

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
},
5353
"autoload-dev": {
5454
"psr-4": {
55-
"Virgil\\Tests\\": "tests/src/"
55+
"Virgil\\Tests\\": "tests/src/",
56+
"Virgil\\Samples\\": "samples/"
5657
}
5758
}
5859
}

phpunit.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<phpunit bootstrap="./tests/bootstrap.php" colors="true">
2+
<testsuites>
3+
<testsuite name="UnitTests">
4+
<directory>./tests/unit/</directory>
5+
</testsuite>
6+
</testsuites>
7+
</phpunit>

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
<directory>./tests/unit/</directory>
55
</testsuite>
66
</testsuites>
7-
</phpunit>
7+
</phpunit>

0 commit comments

Comments
 (0)