PHPackages                             inspirecz/security - 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. inspirecz/security

ActiveLibrary[Security](/categories/security)

inspirecz/security
==================

Security package

v2.0.1(4y ago)129.9kBSD-3-ClausePHPPHP ^8.0CI failing

Since Mar 12Pushed 4y ago1 watchersCompare

[ Source](https://github.com/InspireCZ/security)[ Packagist](https://packagist.org/packages/inspirecz/security)[ Docs](https://github.com/InspireCZ/Security)[ RSS](/packages/inspirecz-security/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (4)Versions (13)Used By (0)

InspireCZ/Security
==================

[](#inspireczsecurity)

[![Latest Version on Packagist](https://camo.githubusercontent.com/5212d0e180ea59f0900a7a0d57637d320c624fb3455bc0bc0f720977e347e1c9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f496e7370697265435a2f53656375726974792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/InspireCZ/Security)[![Software License](https://camo.githubusercontent.com/b60331a2084501dc07cf6d6964c0da58dd005d89c45cf3b28b4b22b60f5ec00f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4253442d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](license.md)[![Build Status](https://camo.githubusercontent.com/2e9c9f529c7aa65d058412a6b14d87fb96b959d0bcbedfb13cd548a1e7010232/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f496e7370697265435a2f53656375726974792f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/InspireCZ/Security)[![Coverage Status](https://camo.githubusercontent.com/99d96bd96c35d5bde0f9dcc0cb69d40a00517da69e65e00a142d323697065e1a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f496e7370697265435a2f53656375726974792e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/InspireCZ/Security/code-structure)[![Quality Score](https://camo.githubusercontent.com/85c69762eed7eac2315527028739579d64e4b9cfe0aea280d4c60381fe3be7d1/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f496e7370697265435a2f53656375726974792e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/InspireCZ/Security)[![Total Downloads](https://camo.githubusercontent.com/320426163cba5410cce52a6514a59acdb965453ba4f1771fbe9240b4acd0221f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f496e7370697265435a2f53656375726974792e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/InspireCZ/Security)

Balíček pro práci se šifrováním a hesly.

Požadavky
---------

[](#požadavky)

InspireCZ/Security vyžaduje PHP 8.0 nebo vyšší.

- [Nette/Security](https://github.com/nette/security)

Instalace
---------

[](#instalace)

Nejlepší způsob jak InspireCZ/Security nainstalovat je pomocí Composeru

```
$ composer require inspirecz/security
```

Použití
-------

[](#použití)

### Symetrické šifrování

[](#symetrické-šifrování)

Pomocí klíče zašifruje, resp. rozšifruje, požadovaná data. Pro šifrování se používá šifra *AES-256-CTR* (klíč musí mít 32 znaků).

```
$hash = 'edb433bdd7c13851c7c68cb31a5acf33';
$symetric = new \Inspire\Security\Crypt\OpenSSLSymetricEncoderDecoder($hash);

$plaintext = 'Hello world!';
$ciphertext = $symetric->encode($plaintext);
echo $symetric->decode($ciphertext); // vystup: Hello world!
```

Pro pohodlné použití v projektu je možné zaregistrovat symetrické šifrování jako službu (např. inject pomocí konstruktoru):

*config.neon*

```
parameters:
    crypt:
        symetrickey: 'edb433bdd7c13851c7c68cb31a5acf33'

service:
    - TestService
    cryptService: \Inspire\Security\Crypt\OpenSSLSymetricEncoderDecoder(%crypt.symetricKey%)
```

*TestService.php*

```
class TestService
{

    /** @var \Inspire\Security\Crypt\OpenSSLSymetricEncoderDecoder */
    private $cryptService;

    /**
     * @param \Inspire\Security\Crypt\OpenSSLSymetricEncoderDecoder $cryptService
     */
    public function __construct(\Inspire\Security\Crypt\OpenSSLSymetricEncoderDecoder $cryptService)
    {
        $this->cryptService = $cryptService;
    }

    /**
     * @param string $text
     *
     * @return string
     */
    public function useCrypt(string $text): string
    {
        return $this->cryptService->encode($text);
    }

}
```

### Šifrování pomocí veřejného/privátního klíče

[](#šifrování-pomocí-veřejnéhoprivátního-klíče)

Balíček obsahuje dvě třídy pro zašifrování, resp. rozšifrování, pomocí veřejného nebo privátního klíče. Základní vlastnost je, že data zašifrovaná veřejným klíčem lze rozšifrovat pouze pomcí privátního klíče a naopak zpráva zašifrovaná priváním klíčem lzde rozšifrovat pouze veřejným klíčem. Privátní klíč může používat heslo, pokud je s ním vygenerovaný.

**Omezení**: Maximální délka data je závislá od použitého klíče. Pro RSA 256 bitů je omezení 245 znaků

```
$publicCrypt = \Inspire\Security\Crypt\OpenSSLPublicKeyCrypt::fromFile('public_key.pem');
$privateCrypt = \Inspire\Security\Crypt\OpenSSLPrivateKeyCrypt::fromFile('private_key.pem', 'passwordForKey');

$plaintext = 'Secret message for private key';
$ciphertext = $publicCrypt->encrypt($plaintext);
echo $privateCrypt->decrypt($ciphertext); // vystup: Secret message for private key

$plaintext = 'Secret message for public key';
$ciphertext = $privateCrypt->encrypt($plaintext);
echo $publicCrypt->decrypt($ciphertext); // vystup: Secret message for public key
```

Vytvořit KeyCrypt objekt můžeme standardně pomocí new a jako parameter konstruktoru předat přímo obsah klíče, nebo můžeme použít pomocnou statickou metodu fromFile. Ta očekává jako parametr cestu k souboru s klíčem a vrací novou instanci crypt objektu.

### Generování hash z hesla a jeho ověření

[](#generování-hash-z-hesla-a-jeho-ověření)

```
$generator = new \Inspire\Security\Password\BCryptPasswordHashGenerator();
$hash = $generator->generate('my-brutal-password');

if ($generator->verify('i-dont-know-my-password', $hash)) {
    echo 'OK';
} else {
    echo 'Try it again';
}

// výstup: Try it again
```

### Generování náhodného tokenu

[](#generování-náhodného-tokenu)

```
$generator = new \Inspire\Security\Password\RandomTokenGenerator();
echo $generator->generate(); // výstup: edb433bdd7c13851c7c68cb31a5acf33
```

Testy
-----

[](#testy)

```
$ vendor/bin/phpunit test
```

Bezpečnost
----------

[](#bezpečnost)

Pokud objevíte jakýkoli bezpečnostní problém, kontaktujte nás prosím na e-mail  místo využití issue.

###  Health Score

37

—

LowBetter than 81% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 75% of commits — single point of failure

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 ~186 days

Recently: every ~192 days

Total

11

Last Release

1535d ago

Major Versions

v1.1.4 → v2.0.02021-08-01

v1.x-dev → v2.0.12022-04-21

PHP version history (3 changes)v1.0.0PHP ^7.0

v2.0.0PHP ^8.0

v1.2.0PHP ^7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/0c233e9fe281989cae2e662f760d8b9796ed88c69f9d353ba9fb5c56017d81b5?d=identicon)[InspireCZ](/maintainers/InspireCZ)

---

Top Contributors

[![mlutonsky](https://avatars.githubusercontent.com/u/423848?v=4)](https://github.com/mlutonsky "mlutonsky (6 commits)")[![JanZahorsky](https://avatars.githubusercontent.com/u/25503866?v=4)](https://github.com/JanZahorsky "JanZahorsky (1 commits)")[![Theery1](https://avatars.githubusercontent.com/u/58081502?v=4)](https://github.com/Theery1 "Theery1 (1 commits)")

---

Tags

securityInspireCZ

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/inspirecz-security/health.svg)

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

###  Alternatives

[phpseclib/phpseclib

PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.

5.6k465.6M1.5k](/packages/phpseclib-phpseclib)[defuse/php-encryption

Secure PHP Encryption Library

3.9k175.2M254](/packages/defuse-php-encryption)[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k18.7M143](/packages/mews-purifier)[robrichards/xmlseclibs

A PHP library for XML Security

41484.3M150](/packages/robrichards-xmlseclibs)[voku/anti-xss

anti xss-library

72817.9M94](/packages/voku-anti-xss)[spatie/laravel-csp

Add CSP headers to the responses of a Laravel app

86611.1M25](/packages/spatie-laravel-csp)

PHPackages © 2026

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