Added test for encryption
This commit is contained in:
parent
4c2bf94417
commit
045abadeb8
2 changed files with 37 additions and 0 deletions
9
tests/third_party/php-encryption/create_random_key.php
vendored
Normal file
9
tests/third_party/php-encryption/create_random_key.php
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?php
|
||||
|
||||
require(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'autoload.php');
|
||||
|
||||
print('Generating new random key' . PHP_EOL);
|
||||
$key = \ncc\Defuse\Crypto\Key::createNewRandomKey();
|
||||
$ascii_key = $key->saveToAsciiSafeString();
|
||||
|
||||
print('Key: ' . $ascii_key . PHP_EOL);
|
28
tests/third_party/php-encryption/encryption_decryption.php
vendored
Normal file
28
tests/third_party/php-encryption/encryption_decryption.php
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
require(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'autoload.php');
|
||||
|
||||
print('Generating new random key' . PHP_EOL);
|
||||
$key = \ncc\Defuse\Crypto\Key::createNewRandomKey();
|
||||
$ascii_key = $key->saveToAsciiSafeString();
|
||||
|
||||
print('Key: ' . $ascii_key . PHP_EOL);
|
||||
|
||||
|
||||
print('Encrypting message \'Hello NCC!\' as raw binary' . PHP_EOL);
|
||||
$encrypted_message = \ncc\Defuse\Crypto\Crypto::encrypt('Hello NCC!', $key, true);
|
||||
print('Encrypted Message: ' . $encrypted_message . PHP_EOL);
|
||||
|
||||
|
||||
print('Decrypting message' . PHP_EOL);
|
||||
$decrypted_message = \ncc\Defuse\Crypto\Crypto::decrypt($encrypted_message, $key, true);
|
||||
print('Decrypted Message: ' . $decrypted_message . PHP_EOL);
|
||||
|
||||
if(hash('md5', 'Hello NCC!') == hash('md5', $decrypted_message))
|
||||
{
|
||||
print('Encryption/Decryption test successful' . PHP_EOL);
|
||||
}
|
||||
else
|
||||
{
|
||||
print('Encryption/Decryption test fail' . PHP_EOL);
|
||||
}
|
Loading…
Add table
Reference in a new issue