PHPackages                             virgil/crypto - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. virgil/crypto

ActiveStandalone[Authentication &amp; Authorization](/categories/authentication)

virgil/crypto
=============

Virgil is a stack of security libraries (ECIES with Crypto Agility wrapped in Virgil Cryptogram) and all the necessary infrastructure to enable seamless, end-to-end encryption for any application, platform or device. See below for currently available languages and platforms. Get in touch with us to get preview access to our key infrastructure.

v7.0.0(1y ago)3319.3k↑88.6%3[1 issues](https://github.com/VirgilSecurity/virgil-crypto-php/issues)[1 PRs](https://github.com/VirgilSecurity/virgil-crypto-php/pulls)2BSD-3-ClausePHPPHP ^8.3CI failing

Since Sep 1Pushed 5mo ago21 watchersCompare

[ Source](https://github.com/VirgilSecurity/virgil-crypto-php)[ Packagist](https://packagist.org/packages/virgil/crypto)[ Docs](http://virgilsecurity.com)[ RSS](/packages/virgil-crypto/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (3)Versions (24)Used By (2)

Virgil Crypto Library PHP
=========================

[](#virgil-crypto-library-php)

[![Build Status](https://github.com/VirgilSecurity/virgil-crypto-php/actions/workflows/build.yml/badge.svg?branch=master)](https://travis-ci.com/VirgilSecurity/virgil-crypto-php)[![GitHub license](https://camo.githubusercontent.com/0baecd984aa7fcf0f699960bfd1e3e345ca00164672d9771025a55f2e306cd71/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d425344253230332d2d436c617573652d626c75652e737667)](https://github.com/VirgilSecurity/virgil/blob/master/LICENSE)[![Latest Version on Packagist](https://camo.githubusercontent.com/959cd7b2ac1db00ceeadadd39e2c97cafe1c98a5593af9998f631badac96b316/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f76697267696c2f63727970746f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/virgil/crypto)[![Total Downloads](https://camo.githubusercontent.com/26ec09dbe139e62e3235a89a979577e7aa2e1aeb668e6988356ee0ef98da0e22/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f76697267696c2f63727970746f2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/virgil/crypto)

[Introduction](#introduction) | [Library purposes](#library-purposes) | [Installation](#installation) | [Usage examples](#usage-examples) | [Docs](#docs) | [License](#license) | [Support](#support)

Introduction
------------

[](#introduction)

Virgil Crypto Library PHP 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.

Library purposes
----------------

[](#library-purposes)

- Asymmetric Key Generation
- Encryption/Decryption of data and streams
- Generation/Verification of digital signatures
- Double Ratchet algorithm support
- **Post-quantum algorithms support**: [Round5](https://round5.org/) (encryption) and [Falcon](https://falcon-sign.info/) (signature)
- Crypto for using [Virgil Core SDK](https://github.com/VirgilSecurity/virgil-sdk-php)

Installation
------------

[](#installation)

**Requirements**:

- PHP 8.2, 8.3

#### Installation via composer

[](#installation-via-composer)

```
composer require virgil/crypto
```

Usage examples
--------------

[](#usage-examples)

### Generate a key pair

[](#generate-a-key-pair)

Generate a key pair using the default algorithm (EC\_X25519):

```
$crypto = new VirgilCrypto();
$keyPair = $crypto->generateKeyPair();
```

### Generate and verify a signature

[](#generate-and-verify-a-signature)

Generate signature and sign data with a private key:

```
$crypto = new VirgilCrypto();
$senderKeyPair = $crypto->generateKeyPair();

// prepare a message
$messageToSign = "Hello, Bob!";

// generate a signature
$signature = $crypto->generateSignature($messageToSign, $senderKeyPair->getPrivateKey());
```

Verify a signature with a public key:

```
$crypto = new VirgilCrypto();

$senderKeyPair = $crypto->generateKeyPair();

// prepare a message
$messageToSign = "Hello, Bob!";

// generate a signature
$signature = $crypto->generateSignature($messageToSign, $senderKeyPair->getPrivateKey());

// verify a signature
$verified = $crypto->verifySignature($signature, $messageToSign, $senderKeyPair->getPublicKey());
```

### Encrypt and decrypt data

[](#encrypt-and-decrypt-data)

Encrypt data with a public key:

```
$crypto = new VirgilCrypto();
$receiverKeyPair = $crypto->generateKeyPair();

// prepare a message
$messageToEncrypt = "Hello, Bob!";

// encrypt the message
$encryptedData = $crypto->encrypt($messageToEncrypt, new VirgilPublicKeyCollection($receiverKeyPair->getPublicKey()));
```

Decrypt the encrypted data with a private key:

```
$crypto = new VirgilCrypto();
$receiverKeyPair = $crypto->generateKeyPair();

// prepare a message
$messageToEncrypt = "Hello, Bob!";

// encrypt the message
$encryptedData = $crypto->encrypt($messageToEncrypt, new VirgilPublicKeyCollection($receiverKeyPair->getPublicKey()));

// prepare data to be decrypted and decrypt the encrypted data using a private key
$decryptedData = $crypto->decrypt($encryptedData, $receiverKeyPair->getPrivateKey());
```

### Import and export keys

[](#import-and-export-keys)

Export keys:

```
use Virgil\CryptoImpl\VirgilCrypto;

$crypto = new VirgilCrypto();
$keyPair = $crypto->generateKeys();

// export private key
$privateKeyData = $crypto->exportPrivateKey($keyPair->getPrivateKey(), "YOUR_PASSWORD");
$privateKeyStr = base64_encode($privateKeyData);

// export public key
$publicKeyData = $crypto->exportPublicKey($keyPair->getPrivateKey());
$publicKeyStr = base64_encode($publicKeyData);

```

Import keys:

```
use Virgil\CryptoImpl\VirgilCrypto;

$crypto = new VirgilCrypto();
$privateKeyStr = "MIGhMF0GCSqGSIb3DQEFDTBQMC8GCSqGSIb3DQEFDDAiBBBtfBoM7VfmWPlvyHuGWvMSAgIZ6zAKBggqhkiG9w0CCjAdBglghkgBZQMEASoEECwaKJKWFNn3OMVoUXEcmqcEQMZ+WWkmPqzwzJXGFrgS/+bEbr2DvreVgEUiLKrggmXL9ZKugPKG0VhNY0omnCNXDzkXi5dCFp25RLqbbSYsCyw=";

$privateKeyData = base64_decode($privateKeyStr);

// import a Private key
$privateKey = $crypto->importPrivateKey($privateKeyData, "YOUR_PASSWORD");

//-----------------------------------------------------

$publicKeyStr = "MCowBQYDK2VwAyEA9IVUzsQENtRVzhzraTiEZZy7YLq5LDQOXGQG/q0t0kE=";

$publicKeyData = base64_decode($publicKeyStr);

// import a Public key
$publicKey = $crypto->importPublicKey($publicKeyData);

```

Additional information
----------------------

[](#additional-information)

- [Manually adding the crypto extension to your server](https://github.com/VirgilSecurity/virgil-cryptowrapper-php#additional-information)

Docs
----

[](#docs)

- [Crypto Core Library](https://github.com/VirgilSecurity/virgil-crypto)
- [Developer Documentation](https://developer.virgilsecurity.com/)

License
-------

[](#license)

This library is released under the [3-clause BSD License](LICENSE).

Support
-------

[](#support)

Our developer support team is here to help you. Find out more information on our [Help Center](https://help.virgilsecurity.com/).

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

Also, get extra help from our support team on [Slack](https://virgilsecurity.com/join-community).

###  Health Score

55

—

FairBetter than 97% of packages

Maintenance55

Moderate activity, may be stable

Popularity37

Limited adoption so far

Community24

Small or concentrated contributor base

Maturity88

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~174 days

Recently: every ~351 days

Total

20

Last Release

641d ago

Major Versions

1.4.0 → 2.0.02016-10-10

2.2.2 → v4.0.02018-05-09

v4.0.0 → v5.0.02018-05-14

v5.1.2 → v6.0.02020-04-02

v6.3.0 → v7.0.02024-09-30

PHP version history (6 changes)1.0.1PHP &gt;=5.3

2.2.2PHP &gt;=5.6

v6.0.0PHP ^7.2

v6.2.0PHP ^7.3|^8

v6.3.0PHP ^8.2

v7.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/dbf68f51108fed58c83419750ce2961ab0e9a82577dde77fd387c5b5a0c60e69?d=identicon)[virgil](/maintainers/virgil)

---

Top Contributors

[![PetrenkoAnton](https://avatars.githubusercontent.com/u/24354013?v=4)](https://github.com/PetrenkoAnton "PetrenkoAnton (81 commits)")[![Qzich](https://avatars.githubusercontent.com/u/3338322?v=4)](https://github.com/Qzich "Qzich (30 commits)")[![sergey-ben](https://avatars.githubusercontent.com/u/1552870?v=4)](https://github.com/sergey-ben "sergey-ben (22 commits)")[![dsuhinin](https://avatars.githubusercontent.com/u/7852635?v=4)](https://github.com/dsuhinin "dsuhinin (20 commits)")[![SergeySeroshtan](https://avatars.githubusercontent.com/u/2228157?v=4)](https://github.com/SergeySeroshtan "SergeySeroshtan (13 commits)")[![MariiaMalitska](https://avatars.githubusercontent.com/u/37335222?v=4)](https://github.com/MariiaMalitska "MariiaMalitska (5 commits)")[![SanjoDeundiak](https://avatars.githubusercontent.com/u/6513916?v=4)](https://github.com/SanjoDeundiak "SanjoDeundiak (1 commits)")

---

Tags

cryptocryptographye2eeencryptionend-to-end-encryptiongdprhipaasecuritycryptographyencryptionAuthenticationplatformverificationcrossPasswordlessellipticdecryptionend-to-endvirgilECIESVirgil.KeysVirgil.PassPerfect Forward SecrecyPFS

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/virgil-crypto/health.svg)

```
[![Health](https://phpackages.com/badges/virgil-crypto/health.svg)](https://phpackages.com/packages/virgil-crypto)
```

###  Alternatives

[virgil/sdk

Virgil is a stack of security libraries (ECIES with Crypto Agility wrapped in Virgil Cryptogram) and all the necessary infrastructure to enable seamless, end-to-end encryption for any application, platform or device. See below for currently available languages and platforms. Get in touch with us to get preview access to our key infrastructure.

1017.6k](/packages/virgil-sdk)[paragonie/sodium_compat

Pure PHP implementation of libsodium; uses the PHP extension if it exists

931145.2M177](/packages/paragonie-sodium-compat)[rinvex/authy

Rinvex Authy is a simple wrapper for Authy TOTP API, the best rated Two-Factor Authentication service for consumers, simplest 2fa Rest API for developers and a strong authentication platform for the enterprise.

36197.6k1](/packages/rinvex-authy)[rinvex/laravel-authy

Rinvex Authy is a simple wrapper for Authy TOTP, the best rated Two-Factor Authentication service for consumers, simplest 2fa Rest API for developers and a strong authentication platform for the enterprise.

3377.3k1](/packages/rinvex-laravel-authy)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
