PHP Classes

File: tests/Backend/ModernCryptoTest.php

Recommend this page to a friend!
  Classes of Scott Arciszewski   Cipher Sweet   tests/Backend/ModernCryptoTest.php   Download  
File: tests/Backend/ModernCryptoTest.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Cipher Sweet
Encrypt data in away that can be searched
Author: By
Last change:
Date: 5 years ago
Size: 870 bytes
 

Contents

Class file image Download
<?php
namespace ParagonIE\CipherSweet\Tests\Backend;

use
ParagonIE\CipherSweet\Backend\ModernCrypto;
use
ParagonIE\CipherSweet\KeyProvider\ArrayProvider;
use
ParagonIE\CipherSweet\KeyProvider\RandomProvider;
use
PHPUnit\Framework\TestCase;

/**
 * Class ModernCryptoTest
 * @package ParagonIE\CipherSweet\Tests
 */
class ModernCryptoTest extends TestCase
{
   
/**
     * @throws \Exception
     */
   
public function testEncrypt()
    {
       
$nacl = new ModernCrypto();
       
$keyProvider = new ArrayProvider($nacl, [
           
ArrayProvider::INDEX_SYMMETRIC_KEY => random_bytes(32)
        ]);

       
$message = 'This is just a test message';
       
$cipher = $nacl->encrypt($message, $keyProvider->getSymmetricKey());
       
$decrypted = $nacl->decrypt($cipher, $keyProvider->getSymmetricKey());

       
$this->assertSame($message, $decrypted);
    }
}