PHP code example of hemiframe / php-aes

1. Go to this page and download the library: Download hemiframe/php-aes 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/ */

    

hemiframe / php-aes example snippets




$aes = new \HemiFrame\Lib\AES();
$aes->setKey("testkey");
$aes->setData("testdata");

$ivString = $aes->generateIv();
$aes->setIv($ivString);

$encryptedString = $aes->encrypt();
$aes->setData($encryptedString);
$decryptedString = $aes->decrypt();

echo "Available methods: " . implode(",", \HemiFrame\Lib\AES::getAvailableMethods()) . "<br/><br/>" . PHP_EOL;
echo "IV string: " . $ivString . "<br/>" . PHP_EOL;
echo "Encrypted string: " . $encryptedString . "<br/>" . PHP_EOL;
echo "Decrypted string: " . $decryptedString . "<br/>" . PHP_EOL;

/**
 * Get encrypt/decrypt key
 * @return string|null
 */
public function getKey(): string

/**
 * Return encoded or decoded string
 * @return mixed
 */
public function getData();

/**
 * Get selected cipher method
 * @return string
 */
public function getMethod(): string

/**
 * Get available cipher methods
 * @return array
 */
public function getAvailableMethods(bool $aliases = false): array

/**
 * Gets selected iv string
 * @return string
 */
public function getIv(): string

/**
 * Generate a iv string for selected method
 * @return string|bool
 */
public function generateIv();

/**
 * Gets the cipher iv length
 * @return int|bool
 */
public function getIvLength();

/**
 * Set encrypt/decrypt key
 * @param string $key
 * @return $this
 * @throws \InvalidArgumentException
 */
public function setKey(string $key): self

/**
 * Set encrypt/decrypt method
 * @param string $method
 * @return $this
 * @throws \InvalidArgumentException
 */
public function setMethod(string $method);

/**
 * Set iv string
 * @param string $iv
 * @return $this
 * @throws \InvalidArgumentException
 */
public function setIv(string $iv): self

/**
 * Set encrypt/decrypt data
 * @param mixed $data
 * @return $this
 * @throws \InvalidArgumentException
 */
public function setData($data): self

/**
 * Returns the encrypted string on success or FALSE on failure.
 * @return string|bool
 * @throws \InvalidArgumentException
 */
public function encrypt();

/**
 * The decrypted string on success or FALSE on failure.
 * @return mixed
 * @throws \InvalidArgumentException
 */
public function decrypt();
json
{
    "emiframe/php-aes": "~1.2"
    }
}