mirror of
https://github.com/friendica/friendica
synced 2025-04-24 21:50:10 +00:00
Reverting php-encryption to version 1.2
This commit is contained in:
parent
1262d6bfee
commit
ccf4dcf270
67 changed files with 931 additions and 6176 deletions
36
vendor/defuse/php-encryption/example.php
vendored
Normal file
36
vendor/defuse/php-encryption/example.php
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
require_once('Crypto.php');
|
||||
try {
|
||||
$key = Crypto::CreateNewRandomKey();
|
||||
// WARNING: Do NOT encode $key with bin2hex() or base64_encode(),
|
||||
// they may leak the key to the attacker through side channels.
|
||||
} catch (CryptoTestFailedException $ex) {
|
||||
die('Cannot safely create a key');
|
||||
} catch (CannotPerformOperationException $ex) {
|
||||
die('Cannot safely create a key');
|
||||
}
|
||||
|
||||
$message = "ATTACK AT DAWN";
|
||||
try {
|
||||
$ciphertext = Crypto::Encrypt($message, $key);
|
||||
} catch (CryptoTestFailedException $ex) {
|
||||
die('Cannot safely perform encryption');
|
||||
} catch (CannotPerformOperationException $ex) {
|
||||
die('Cannot safely perform decryption');
|
||||
}
|
||||
|
||||
try {
|
||||
$decrypted = Crypto::Decrypt($ciphertext, $key);
|
||||
} catch (InvalidCiphertextException $ex) { // VERY IMPORTANT
|
||||
// Either:
|
||||
// 1. The ciphertext was modified by the attacker,
|
||||
// 2. The key is wrong, or
|
||||
// 3. $ciphertext is not a valid ciphertext or was corrupted.
|
||||
// Assume the worst.
|
||||
die('DANGER! DANGER! The ciphertext has been tampered with!');
|
||||
} catch (CryptoTestFailedException $ex) {
|
||||
die('Cannot safely perform encryption');
|
||||
} catch (CannotPerformOperationException $ex) {
|
||||
die('Cannot safely perform decryption');
|
||||
}
|
||||
?>
|
Loading…
Add table
Add a link
Reference in a new issue