I'm trying to encrypt a word with a key
and i found out openssl_encrypt
.
Now (maybe) i'm able to do it but i can't to extract from it initial word and secret key.
$text = "message";
$method = "aes-128-gcm";
$ivlen = openssl_cipher_iv_length($method);
$iv = openssl_random_pseudo_bytes($ivlen);
$secretKey= "god";
if (in_array($method, openssl_get_cipher_methods())){
$encrypted = openssl_encrypt($text, $method, $secretKey, $options=0, $iv);
$decrypted = openssl_decrypt($encrypted, $method, $secretKey, $options=0, $iv);
print_r($encrypted);
print_r($decrypted);
}
Besides when decryption is correct output is FALSE or TRUE ?