Я пытаюсь написать веб-страницу, и я реализовал две функции для шифрования и дешифрования строки с помощью функций openssl.
Функция шифрования с использованием openssl:
checkInputs () является самореализуемой функцией и возвращает htmlspecialchars ()
function encode($data) {
$data = checkInputs($data);
# Crypting with openssl method
// Store the cipher method
// Store cipher method
$ciphering = "BF-CBC";
// Use OpenSSl encryption method
$iv_length = openssl_cipher_iv_length($ciphering);
$options = 0;
// Use random_bytes() function which gives
// randomly 16 digit values
$encryption_iv = random_bytes($iv_length);
// Alternatively, we can use any 16 digit
// characters or numeric for iv
$encryption_key = openssl_digest(php_uname(), 'MD5', TRUE);
// Encryption of string process starts
$encryption = openssl_encrypt($data, $ciphering, $encryption_key, $options, $encryption_iv);
return $encryption;
}
Функция дешифрования с использованием openssl:
function decode($data) {
#codes to decode data
$ciphering = "BF-CBC";
$iv_length = openssl_cipher_iv_length($ciphering);
$options = 0;
$decryption_iv = random_bytes($iv_length);
$decryption_key = openssl_digest(php_uname(), 'MD5', TRUE);
$decryption = openssl_decrypt ($data, $ciphering, $decryption_key, $options, $decryption_iv);
return $decryption;
}
Проблема в том, что кодирование ($ string) не совпадает с декодированием ($ string).
$string = "Welcome";
if( encode($string) == decode($string) ) {
...
} // returns FALSE, and the condition isn't true as well.