Skip to content
/ crypt Public

Small library for encryption via phpseclib

License

Notifications You must be signed in to change notification settings

SiViN/crypt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

crypt

Small library for encryption via phpseclib

Build Status License Total Downloads

  1. Install via composer

    composer require sivin/crypt
  2. Register extension in config.neon:

    extensions:
    	crypt: SiViN\Crypt\DI\CryptExtension
  3. 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'];
  4. 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

  5. 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);

About

Small library for encryption via phpseclib

Resources

License

Stars

Watchers

Forks

Packages

No packages published