sivin / crypt
Small library for encryption via phpseclib
Installs: 7 383
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: >= 7.1
- ext-openssl: *
- nette/di: ~3.0
- phpseclib/phpseclib: ^3.0
- tracy/tracy: ^2.6
Requires (Dev)
- ninjify/nunjuck: ^0.3.0@dev
This package is auto-updated.
Last update: 2024-12-20 16:10:24 UTC
README
Small library for encryption via phpseclib
-
Install via composer
composer require sivin/crypt
-
Register extension in
config.neon
:extensions: crypt: SiViN\Crypt\DI\CryptExtension
-
Create or use your key/s:
/** @var Crypt */ private $crypt; public function __construct(Crypt $crypt) { $this->crypt = $crypt; } ... $keys = $this->crypt->createKeyPair() $privateKeyRaw = $keys['privateKeyRaw']; $publicKeyRaw = $keys['publicKeyRaw'];
-
Use your own key or define it in a
config.local.neon
:$crypt->setPublicKey($myPublicKeyForEncrypt); $crypt->setPrivateKey($myPrivateKeyForDecrypt); //if there is a private key with a password $crypt->setPrivateKeyPassword($myPivateKeyPasswordForDecrypt);
or in a
config.local.neon
:crypt: publicKeyPath: publicKeyFile.pub #for encrypting privateKeyPath: privateKeyFile.key #for decrypting privateKeyPassword: 'PrivateKeyPassword' #optional
If you only want to encrypt/decrypt, just define the encrypting/decrypting key
-
And finally?:
$encryptedStr = $crypt->encryptRijndaelMessage($stringToEncode); //for transport $decryptedStr = $crypt->decryptRijndaelMessage($encryptedStr); $encryptedStr = $crypt->encryptRsa($stringToEncode); $decryptedStr = $crypt->decryptRsa($encryptedStr); $encryptedStr = $crypt->encryptRijndael($stringToEncode); $decryptedStr = $crypt->decryptRijndael($encryptedStr);