BASE . LOG, 'log_file_id' => $LOG_FILE_ID, 'log_per_date' => true, ]); // define a list of from to color sets for conversion test $PAGE_NAME = 'TEST CLASS: ENCRYPTION'; print ""; print "" . $PAGE_NAME . ""; print ""; print '
Class Test Master
'; print '

' . $PAGE_NAME . '

'; $key = CreateKey::generateRandomKey(); print "Secret Key: " . $key . "
"; $string = "I a some deep secret"; // $crypt = new SymmetricEncryption($key); $encrypted = $crypt->encrypt($string); $decrypted = $crypt->decrypt($encrypted); print "[C] Encrypted: " . $encrypted . "
"; print "[C] Decrytped: " . $decrypted . "
"; $encrypted = SymmetricEncryption::getInstance($key)->encrypt($string); $decrypted = SymmetricEncryption::getInstance($key)->decrypt($encrypted); print "[S] Original: " . $string . "
"; print "[S] Encrypted: " . $encrypted . "
"; print "[S] Decrytped: " . $decrypted . "
"; $encrypted = SymmetricEncryption::encryptKey($string, $key); $decrypted = SymmetricEncryption::decryptKey($encrypted, $key); print "[SS] Encrypted: " . $encrypted . "
"; print "[SS] Decrytped: " . $decrypted . "
"; print "
INIT KEY MISSING
"; try { $crypt = new SymmetricEncryption(); $encrypted = $crypt->decrypt($string); } catch (Exception $e) { print("Error: " . $e->getMessage() . "
"); } print "
WRONG CIPHERTEXT
"; try { $decrypted = SymmetricEncryption::decryptKey('flupper', $key); } catch (Exception $e) { print "Error: " . $e->getMessage() . "
"; } print "
SHORT and WRONG KEY
"; $key = 'wrong_key'; try { $encrypted = SymmetricEncryption::encryptKey($string, $key); } catch (Exception $e) { print "Error: " . $e->getMessage() . "
"; } print "
INVALID HEX KEY
"; $key = '1cabd5cba9e042f12522f4ff2de5c31d233b'; try { $encrypted = SymmetricEncryption::encryptKey($string, $key); } catch (Exception $e) { print "Error: " . $e->getMessage() . "
"; } print "
WRONG KEY TO DECRYPT
"; $key = CreateKey::generateRandomKey(); $string = "I a some deep secret"; $encrypted = SymmetricEncryption::encryptKey($string, $key); $key = 'wrong_key'; try { $decrypted = SymmetricEncryption::decryptKey($encrypted, $key); } catch (Exception $e) { print "Error: " . $e->getMessage() . "
"; } print ""; // __END__