PHPackages                             mglinski/ecc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. mglinski/ecc

ActiveLibrary[Security](/categories/security)

mglinski/ecc
============

PHP Elliptic Curve Cryptography library

v0.3.2(11y ago)02.1k2MITPHPPHP &gt;=5.4.0

Since Jul 7Pushed 10y ago1 watchersCompare

[ Source](https://github.com/mglinski/phpecc)[ Packagist](https://packagist.org/packages/mglinski/ecc)[ Docs](https://github.com/mdanter/phpecc)[ RSS](/packages/mglinski-ecc/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (5)Used By (2)

Pure PHP Elliptic Curve DSA and DH
----------------------------------

[](#pure-php-elliptic-curve-dsa-and-dh)

[![Build Status](https://camo.githubusercontent.com/3d8fbab857eb36b38e9ebce84f69fa38965b287224d0c685c4f25fdc0711dce7/68747470733a2f2f7472617669732d63692e6f72672f6d64616e7465722f7068706563632e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mdanter/phpecc)[![HHVM Status](https://camo.githubusercontent.com/f3895bfedf06b3724e57ef8eea30a73cc06d802059206dc84788b4746c33ea9d/687474703a2f2f6868766d2e683463632e64652f62616467652f6d64616e7465722f6563632e737667)](http://hhvm.h4cc.de/package/mdanter/ecc)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/8638662499bdedab5a12e72197eaf1be627535c1636b0989f02ebb81cf4f0f65/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d64616e7465722f7068706563632f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mdanter/phpecc?branch=master)[![Code Coverage](https://camo.githubusercontent.com/48002061341bd8b68a97f45c98d3cb4d69affc6f1aae2ce36564d68f586b84eb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d64616e7465722f7068706563632f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mdanter/phpecc/?branch=master)

[![Latest Stable Version](https://camo.githubusercontent.com/835a6b9022806290819dda9f286818d1bfe4770d317b0bce20c6c67e9ad9fa50/68747470733a2f2f706f7365722e707567782e6f72672f6d64616e7465722f6563632f762f737461626c652e706e67)](https://packagist.org/packages/mdanter/ecc)[![Total Downloads](https://camo.githubusercontent.com/7a6d440f545f1b728e03ee05ed80e50f55707b1f0db6b5e313d00a69934093c0/68747470733a2f2f706f7365722e707567782e6f72672f6d64616e7465722f6563632f646f776e6c6f6164732e706e67)](https://packagist.org/packages/mdanter/ecc)[![Latest Unstable Version](https://camo.githubusercontent.com/d3a98e28f85d926b4bd07460e9fd0c03acec43036d3ab31b776b648e62683b58/68747470733a2f2f706f7365722e707567782e6f72672f6d64616e7465722f6563632f762f756e737461626c652e706e67)](https://packagist.org/packages/mdanter/ecc)[![License](https://camo.githubusercontent.com/38b47d81c8f5b32ccaef6289bb927fa12d1fd02f249355919ff65f41017dc92e/68747470733a2f2f706f7365722e707567782e6f72672f6d64616e7465722f6563632f6c6963656e73652e706e67)](https://packagist.org/packages/mdanter/ecc)

### Information

[](#information)

This library is a rewrite/update of Matyas Danter's ECC library. All credit goes to him.

For more information on Elliptic Curve Cryptography please read [this fine article](http://www.matyasdanter.com/2010/12/elliptic-curve-php-oop-dsa-and-diffie-hellman/).

### License

[](#license)

This package is released under the MIT license.

### Requirements

[](#requirements)

- PHP 5.4+
- composer
- ext-gmp
- ext-mcrypt

### Installation

[](#installation)

You can install this library via Composer :

`composer require mdanter/ecc`

### Contribute

[](#contribute)

When sending in pull requests, please make sure to run the `make` command.

The default target runs all PHPUnit and PHPCS tests. All tests must validate for your contribution to be accepted.

It's also always a good idea to check the results of the [Scrutinizer analysis](https://scrutinizer-ci.com/g/mdanter/phpecc/) for your pull requests.

### Usage

[](#usage)

**WARNING** Though this library is tested for compliance to standards, it is subject to at least one documented vulnerability in public-key derivation, which can potentially allow attackers to grab your private keys. **USE AT YOUR OWN RISK**. You've been warned.

**WARNING** All following documentation is based off the master branch, not the tagged versions.

#### Key generation

[](#key-generation)

##### The lazy way

[](#the-lazy-way)

You're in luck, there's a command line tool ! The examples assume that phpecc (found in the bin/ folder) is on your path.

Generate a private/public keypair:

```
$ phpecc genkey --curve=nist-p256 --out=pem
Using curve "nist-p256"
-----BEGIN EC PRIVATE KEY-----
MHYCAQEEHxMDwxsmFiNDNtNXZIfDm7xYlwJU3YedMA3zyhz/0+OgCgYIKoZIzj0D
AQehRANCAATHZZfy/pz9cqrVldcbtM2ucDYahx8IZZWY8/txTGfmwE9VhZDxh2w6
rJruv+3BMOmKqI42MvpuE02U+Rhlf9ch
-----END EC PRIVATE KEY-----
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEx2WX8v6c/XKq1ZXXG7TNrnA2Gocf
CGWVmPP7cUxn5sBPVYWQ8YdsOqya7r/twTDpiqiONjL6bhNNlPkYZX/XIQ==
-----END PUBLIC KEY-----

```

Alternately, you can pipe the output to file:

```
$ phpecc genkey --curve=nist-p256 --out=pem > keypair.pem
Using curve "nist-p256"

```

The generated keys *should* be compatible with OpenSSL. However, if you find cases where OpenSSL cannot parse a key generated using `phpecc`, please submit an issue with the parameters used to generate your key.

**Note**: you don't actually need the public key part from the output, it's also encoded in the private key segment.

To get the list of supported curves :

```
$ phpecc list-curves
nist-p192
nist-p224
nist-p256
nist-p384
nist-p521
secp256k1
secp384r1
```

##### The developper way

[](#the-developper-way)

TODO...

#### Asymmetric encryption

[](#asymmetric-encryption)

##### The dead stupid example:

[](#the-dead-stupid-example)

```
