https://github.com/paragonie/easy-ecc
High-Level Usability Wrapper for PHPECC
https://github.com/paragonie/easy-ecc
Last synced: 12 months ago
JSON representation
High-Level Usability Wrapper for PHPECC
- Host: GitHub
- URL: https://github.com/paragonie/easy-ecc
- Owner: paragonie
- License: other
- Created: 2018-02-11T20:53:38.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2024-09-03T23:44:32.000Z (over 1 year ago)
- Last Synced: 2025-02-23T23:11:20.700Z (12 months ago)
- Language: PHP
- Size: 63.5 KB
- Stars: 44
- Watchers: 8
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Easy-ECC
[](https://github.com/paragonie/easy-ecc/actions)
[](https://packagist.org/packages/paragonie/easy-ecc)
[](https://packagist.org/packages/paragonie/easy-ecc)
[](https://packagist.org/packages/paragonie/easy-ecc)
[](https://packagist.org/packages/paragonie/easy-ecc)
A usability wrapper for [PHP ECC](https://github.com/paragonie/phpecc)
that also further hardens against timing attacks.
## Installing
```
composer require paragonie/easy-ecc
```
## Using Easy-ECC
```php
generatePrivateKey();
$alice_pk = $alice_sk->getPublicKey();
// Signing a message (with PEM-formatted signatures):
$message = 'This is extremely simple to use correctly.';
$signature = $ecc->sign($message, $alice_sk);
if (!$ecc->verify($message, $alice_pk, $signature)) {
throw new Exception('Signature validation failed');
}
// Let's do a key exchange:
$bob_sk = $ecc->generatePrivateKey();
$bob_pk = $alice_sk->getPublicKey();
$alice_to_bob = $ecc->keyExchange($alice_sk, $bob_pk, true);
$bob_to_alice = $ecc->keyExchange($bob_sk, $alice_pk, false);
```
### Other Easy-ECC Modes
#### secp256k1 + SHA256
```php
generatePrivateKey();
/** @var PublicKey $alice_pk */
$alice_pk = $alice_sk->getPublicKey();
// Serialize as PEM (for OpenSSL compatibility):
$alice_sk_pem = $alice_sk->exportPem();
$alice_pk_pem = $alice_pk->exportPem();
// Serialize public key as compressed point (for brevity):
$alice_pk_cpt = $alice_pk->toString();
$message = 'This is extremely simple to use correctly.';
// Signing a message (with IEEE-P1363-formatted signatures):
$signature = $ecc->sign($message, $alice_sk, true);
if (!$ecc->verify($message, $alice_pk, $signature, true)) {
throw new Exception('Signature validation failed');
}
// Let's do a key exchange:
$bob_sk = $ecc->generatePrivateKey();
$bob_pk = $alice_sk->getPublicKey();
$alice_to_bob = $ecc->keyExchange($alice_sk, $bob_pk, true);
$bob_to_alice = $ecc->keyExchange($bob_sk, $alice_pk, false);
```
### Asymmetric Encryption
We provide an interface that you can implement for the underlying symmetric
cryptography to suit your needs. This library provides a built-in integration
for [Defuse's PHP encryption library](https://github.com/defuse/php-encryption).
```php
seal($superSecret, $publicKey);
$opened = $defuse->unseal($sealed, $secretKey);
// Or you can encrypt between two keypairs:
$otherSecret = $ecc->generatePrivateKey();
$otherPublic = $otherSecret->getPublicKey();
$encrypted = $defuse->asymmetricEncrypt($superSecret, $secretKey, $otherPublic);
$decrypted = $defuse->asymmetricDecrypt($encrypted, $otherSecret, $publicKey);
```
## Support Contracts
If your company uses this library in their products or services, you may be
interested in [purchasing a support contract from Paragon Initiative Enterprises](https://paragonie.com/enterprise).