PHP code example of sivin / crypt

1. Go to this page and download the library: Download sivin/crypt library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sivin / crypt example snippets


	extensions:
		crypt: SiViN\Crypt\DI\CryptExtension
	

	/** @var Crypt */
	private $crypt;

	public function __construct(Crypt $crypt)
	{
		$this->crypt = $crypt;
	}
	...
	$keys = $this->crypt->createKeyPair()
	$privateKeyRaw = $keys['privateKeyRaw'];
	$publicKeyRaw = $keys['publicKeyRaw'];
	

	$crypt->setPublicKey($myPublicKeyForEncrypt);
	$crypt->setPrivateKey($myPrivateKeyForDecrypt);
	//if there is a private key with a password
	$crypt->setPrivateKeyPassword($myPivateKeyPasswordForDecrypt);
	

	crypt:
		publicKeyPath: publicKeyFile.pub #for encrypting
		privateKeyPath: privateKeyFile.key #for decrypting
		privateKeyPassword: 'PrivateKeyPassword' #optional
	

	$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);